How to depend on other module from buildSrc


I currently have a composite build with the following structure:

* Library
    * src
* Application
    * buildSrc
    * src

The root project settings.gradle looks as follows:

includeBuild 'Library'
includeBuild 'Application'

I would like to have the library module as a dependency in the buildSrc of my Application. Is this possible and if so how? Just adding it as a dependency doesn’t seem to work.

Kind regards,

" The directory buildSrc is treated as an included build. Upon discovery of the directory, Gradle automatically compiles and tests this code and puts it in the classpath of your build script. For multi-project builds there can be only one buildSrc directory, which has to sit in the root project directory. buildSrc should be preferred over script plugins as it is easier to maintain, refactor and test the code."

“A build that is included in a composite build is referred to, naturally enough, as an “included build”. Included builds do not share any configuration with the composite build, or the other included builds. Each included build is configured and executed in isolation.”

That being said I have noticed that sometimes my IDE does not recognize changes in buildSrc/build.gradle.kts
I suspect this is due to an oversight by the Intellij people.

yes but you should be able to declare dependencies between included builds as a binary dependency. This also seems to be possible for every included build except the buildSrc.

1 Like

buildSrc should be accessible via gradle.includedBuilds but it is not.
I would need to access this to get a jar created via a buildSrc module, for now I resort to using the jar path as hard coded, but a configuration would be just the normal way to get this jar with gradle.

One strategy to make builldSrc more like an included build is to replace it with an actual included build. There are a number of advantages to this. The main build can still use plugins and other classes from projects in the included build, just like buildSrc, but also:

  • Projects in the main build can depend on projects in the included build, as so use their outputs, such as the Jar
  • Your can depend on tasks from the included build from the main build
  • You can publish the plugins and other libraries defined in the included build
  • The tests and other checks for the projects in the included build are not run for every build, like they are for buildSrc.

Of course, it would be better if buildSrc worked the same way, and over time we will remove the differences.

Thank you very much Adam.
I was thinking of this workaround to normalize the builSrc as an included build.