HowTo : control build order of gradle subprojects submodules?


(hanasaki jiji) #1

How do you control the build order of subprojects submodules of a parent project? The order seems to be based on natural string ordering of the “name” I did try setting the directories of the subprojects as 00-… 01-… etc and setting their names in the parent settings.gradle. The build order was in the order of the project names not the directories.

The objective is to have subprojects in directories named module-00… etc. and have this control the build order while the project name (set in settings.gradle) is used to control all the artifacts (.jar, …-sources.jar etc…)

Thank you.


(Daryl) #2

Is there a reason for order to be important? If there is a dependency, you should set that up so Gradle can manage the task graph and dependency order… if order is important but you don’t have dependencies, then perhaps you are missing declaring a dependency that was assumed by buildscript order…


(hanasaki jiji) #3

Yes. There is a reason. The goal is to have a parent project that builds its subprojects in a specific order that represents the layering of API’s/Implementations from the bottom up (think “ISO layers”)

  • Build a layer
  • Test a layer
  • Produce artifacts (jar, sources jar, test jar, test-sources jar)
  • Publish to mavenlocal including pom.xml
  • Publish to http repository including pom.xml (optional)
  • repeat with the next layer “higher” which also includes this layer as a compile dependency. (not a project dependency - want the JAR pulled from mavenlocal/mvnrepo)

?? 1. note the published pom runs into https://github.com/gradle/gradle/issues/1118 however the project task createPom { pom… does make the correct pom-generated.xml anyway to make the publish mavenlocal publish this instead of the wrong one it autocreates in build default


(Fred Curts) #4

That’s not how Gradle (and most other build tools) work. Execution dependencies are between tasks, not between projects. Project names perhaps affect the configuration order (I wouldn’t rely on it) but not the build order.


(hanasaki jiji) #5

Thank you. Really good point! I guess what is needed here is for each subfolder/subdirectory to be built (based on specified order or order of directory alpha sorted) - as its own build; spawned and serially. Thoughts?

In this case, from bottom to top

  • spring boot exec for use with bash etc…
  • gradle plugin
  • common functionality for both of the above

TIA.


(Fred Curts) #6

I’d seriously reconsider if and why you need multiple builds. It will complicate matters significantly.


(hanasaki jiji) #7

what would you suggest to accomplish the stated goals?


(Fred Curts) #8

I’d question the stated goals. It sounds like you want Gradle to work like Maven, and it’s not clear why.