Sometimes, you may also need to share build logic between
buildSrc
itself and your root build. In the previous releases, that was not possible becausebuildSrc
could not access build logic from other included builds.In this release, it’s now possible to share build logic between buildSrc and the root build or any other included build. This makes it easier to share common repository declarations or conventions between buildSrc and other builds as demonstrated in this sample.
I need to share some code between buildSrc
and subproject
. So, I extracted that code into a separate gradle project (commons
) and tried to link it as an included build in order to use it as a dependency in buildSrc
and subproject
. Something like this:
gradle-composite-bug (root directory)
gradle-composite-bug (root)
buildSrc
subproject
commons (our "included build")
I’ve created the sample which corresponds to the structure above. And it seems to work but with some caveats.
First item. buildSrc
is not building separately. It emits the error. The whole root/subproject/commons are building fine. Is it okay ? It seems not to disturb me.
cd gradle-composite-bug/buildSrc
gradle build
Second item. Intelij IDEA doesn’t put commons
on buildSrc's
classpath. And as result, autocomplete doesn’t work. It’s the most serious problem, because those classes have quite interesting API that will definitely sophisticate my life without autocomplete. And IDE that permanently reports errors - is not fine at all. But it works fine with subproject
where IDE have put commons
on the classpath.
I’m not sure, but may be it’s because IDE differently sees these dependencies. They are declared similarly in corresponding gradle.build.kts
files, but for buildSrc
it’s a plain library, and for subproject
it’s a full-fledged project.
In
buildSrc's
module configuration/Dependencies tab IDE reports Library 'Gradle::commons:' has broken path.
So, I have several questions:
- Did I misconfigure the project ? But, generally It works as intended, via terminal, of course)
- First item doesn’t bother me and I’m not sure if it’s a problem at all. But if yes - it’s definitely a Gradle’s one. And the bug should be reported to them.
- Second item is critical. It’s kind of hard to work without autocomplete and with all your code being highlighted red. Is it because I misconfigured Gradle or IDE ? Or it’s a Gradle / IDE’s problem ?
Any help/thoughts/suggestions will be appreciated I’m afraid I’m already stuck.