# Multi-project build - project dependencies and build order

**URL:** <https://discuss.gradle.org/t/multi-project-build-project-dependencies-and-build-order/19846>\
**Category:** Help/Discuss\
**Created:** [October 3, 2016, 7:27pm UTC](https://discuss.gradle.org/t/multi-project-build-project-dependencies-and-build-order/19846 "2016-10-03T19:27:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daven53](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daven53/32/5625_2.png) [@Daven53](https://discuss.gradle.org/u/Daven53)\
**Post date:** [October 3, 2016, 7:27pm UTC](https://discuss.gradle.org/t/multi-project-build-project-dependencies-and-build-order/19846/1 "2016-10-03T19:27:38Z")

</div>

I need to migrate a multi-project build from maven to gradle and maintain the way inter-project dependencies and build order work. I’d like to use the maven plugin in gradle and continue to publish artifacts to both local and remote maven repositories.

The multi-project structure is like so:  
`root/`  
`--Project-A/`  
`----Project-A1/`  
`----Project-A2/`  
`--Project-B/`  
`----Project-B1/`  
`----Project-B2/`

In maven _Project-A2_ has a dependency on _Project-A1_. If I run mvn install\_ from the _Project-A2_ directory it will only build/install that project and pull it’s dependency on _Project-A1_ from the local/remote maven repository. If I run mvn install from _Project-A_ it will build/install both _Project-A1_ and _A2_ and calculate the build order based on the above mentioned dependency. How can this same behavior be achieved in gradle?

Additionally, _Project-B2_ has a dependency on _Project-A2_. If I run mvn install from the _Project-B2_ or _Project-B_ directories this dependency should be pulled from the local/remote maven repository. If I run mvn install from the _root_ directory it should calculate the build order such that _Project-A1_ builds, \_Project-A2 builds, and then _Project-B2_ builds.

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [October 4, 2016, 9:57am UTC](https://discuss.gradle.org/t/multi-project-build-project-dependencies-and-build-order/19846/2 "2016-10-04T09:57:04Z")

</div>

> [@Daven53](#):
>
> If I run mvn install\_ from the Project-A2 directory it will only build/install that project and pull it’s dependency on Project-A1 from the local/remote maven repository.

Could you explain why you want to mimic this behavior in Gradle? Why not build Project-A1? Gradle has excellent support for incremental builds, so this will be fast and correct.

---

<div class="post-metadata">

**Author:** ![Daven53](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daven53/32/5625_2.png) [@Daven53](https://discuss.gradle.org/u/Daven53)\
**Post date:** [October 5, 2016, 9:13pm UTC](https://discuss.gradle.org/t/multi-project-build-project-dependencies-and-build-order/19846/3 "2016-10-05T21:13:08Z")

</div>

The main concern is build time. If it were simply one small project depending on another it’s not really an issue. I’m working with a number of cases where a relatively small project depends on one or more larger projects. If the project I want to build takes 5 minutes but it’s dependencies take 30 minutes it’s not ideal to build both and end up with a 35 minute build time.

The incremental build support is great and after building everything once it looks like it should address this need. However I do need to consider the case where someone checks out the source fresh and only wants to build a small piece. They’re not going to want to wait for multiple dependencies to build when they could be pulled in from a repository.

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [October 6, 2016, 8:43am UTC](https://discuss.gradle.org/t/multi-project-build-project-dependencies-and-build-order/19846/4 "2016-10-06T08:43:27Z")

</div>

> [@Daven53](#):
>
> If the project I want to build takes 5 minutes but it’s dependencies take 30 minutes it’s not ideal to build both and end up with a 35 minute build time.

Are these real numbers or hypothetical? Note that the upstream dependencies only need to create their outputs. They won’t run tests or other time-consuming tasks.

If your projects actually take that long just to compile, then you might be interested in either:

- breaking your big build into smaller builds (inside the same repo) using [Composite Builds](https://docs.gradle.org/current/userguide/composite_builds.html)
- our upcoming distributed cache support

---

<div class="post-metadata">

**Author:** ![Daven53](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daven53/32/5625_2.png) [@Daven53](https://discuss.gradle.org/u/Daven53)\
**Post date:** [October 6, 2016, 7:59pm UTC](https://discuss.gradle.org/t/multi-project-build-project-dependencies-and-build-order/19846/5 "2016-10-06T19:59:57Z")

</div>

Those numbers are hypothetical but our total build time does reach between 2-3 hours without test and there are cases that exist similar to that example.

I’ll take a look at composite builds and the distributed cache support. It sounds like a little restructuring of the projects/process to better fit gradle is the direction to go. Thanks for the suggestions!

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [October 8, 2016, 10:14pm UTC](https://discuss.gradle.org/t/multi-project-build-project-dependencies-and-build-order/19846/6 "2016-10-08T22:14:10Z")

</div>

Maybe I misunderstood your description: Is the 2-3h build time with Maven or Gradle? Gradle is much faster than Maven, so I’d suggest first going with the straightforward multi-project approach and only optimizing if you actually hit a problem.

---

<div class="post-metadata">

**Author:** ![Daven53](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daven53/32/5625_2.png) [@Daven53](https://discuss.gradle.org/u/Daven53)\
**Post date:** [October 11, 2016, 2:52pm UTC](https://discuss.gradle.org/t/multi-project-build-project-dependencies-and-build-order/19846/7 "2016-10-11T14:52:04Z")

</div>

2-3 hours in maven. I don’t have an estimate for gradle yet due to trying to work out the best approach ahead of converting the entire maven build to gradle. I’ve only been working with a small piece of our source with gradle.

If the best way to tackle this is to setup the multi-project and then look into composite builds, distributed cache support etc. then that’s what I’ll do. I assumed that we would see similar build time/dependency related problems in gradle as we do in maven but if that’s not the case that’s great. Thanks!
