# How to depend on other module from buildSrc

**URL:** <https://discuss.gradle.org/t/how-to-depend-on-other-module-from-buildsrc/34004>\
**Category:** Help/Discuss\
**Created:** [November 25, 2019, 11:09am UTC](https://discuss.gradle.org/t/how-to-depend-on-other-module-from-buildsrc/34004 "2019-11-25T11:09:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bartvhelvert](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@Bartvhelvert](https://discuss.gradle.org/u/Bartvhelvert)\
**Post date:** [November 25, 2019, 11:09am UTC](https://discuss.gradle.org/t/how-to-depend-on-other-module-from-buildsrc/34004/1 "2019-11-25T11:09:11Z")

</div>

Hi,

I currently have a composite build with the following structure:

```gradle
* Library
    * src
* Application
    * buildSrc
    * src

```

The root project settings.gradle looks as follows:

```gradle
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,

Bart

---

<div class="post-metadata">

**Author:** ![phreed](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@phreed](https://discuss.gradle.org/u/phreed)\
**Post date:** [November 25, 2019, 2:50pm UTC](https://discuss.gradle.org/t/how-to-depend-on-other-module-from-buildsrc/34004/2 "2019-11-25T14:50:46Z")

</div>

[https://docs.gradle.org/current/userguide/organizing\_gradle\_projects.html#sec:build\_sources](https://docs.gradle.org/current/userguide/organizing_gradle_projects.html#sec:build_sources)  
" The directory `buildSrc` is treated as an [included build](https://docs.gradle.org/current/userguide/composite_builds.html#composite_build_intro). 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](https://docs.gradle.org/current/userguide/plugins.html#sec:script_plugins) as it is easier to maintain, refactor and test the code."

…and…

[https://docs.gradle.org/current/userguide/composite\_builds.html#composite\_build\_intro](https://docs.gradle.org/current/userguide/composite_builds.html#composite_build_intro)  
“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.

---

<div class="post-metadata">

**Author:** ![Bartvhelvert](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@Bartvhelvert](https://discuss.gradle.org/u/Bartvhelvert)\
**Post date:** [November 25, 2019, 6:48pm UTC](https://discuss.gradle.org/t/how-to-depend-on-other-module-from-buildsrc/34004/3 "2019-11-25T18:48:34Z")

</div>

> [@phreed](#):
>
> atically compiles and tests this code and puts it in the classpath of your build script. For multi-project builds there can be only one `buil`

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.

---

<div class="post-metadata">

**Author:** ![Stephane\_NICOLAS](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stephane_nicolas/32/1526_2.png) [@Stephane\_NICOLAS](https://discuss.gradle.org/u/Stephane_NICOLAS)\
**Post date:** [February 14, 2020, 1:43pm UTC](https://discuss.gradle.org/t/how-to-depend-on-other-module-from-buildsrc/34004/4 "2020-02-14T13:43:39Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![adammurdoch](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/adammurdoch/32/17_2.png) [@adammurdoch](https://discuss.gradle.org/u/adammurdoch)\
**Post date:** [February 16, 2020, 8:15pm UTC](https://discuss.gradle.org/t/how-to-depend-on-other-module-from-buildsrc/34004/5 "2020-02-16T20:15:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Stephane\_NICOLAS](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stephane_nicolas/32/1526_2.png) [@Stephane\_NICOLAS](https://discuss.gradle.org/u/Stephane_NICOLAS)\
**Post date:** [February 16, 2020, 11:12pm UTC](https://discuss.gradle.org/t/how-to-depend-on-other-module-from-buildsrc/34004/6 "2020-02-16T23:12:31Z")

</div>

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