I have a multi-project setup all the subprojects build out of the same directory hierarchy. eg they are all unzipped on top of each other in the root directory, and have to coordinate amongst themselves to avoid file collisions. Unfortunately changing this structure is not an option.
The subprojects all have zero or more compile dependencies on each other, which are defined externally. We have other tools that also require this information, so we cannot migrate the dependency definitions into the projects themselves.
The current strategy I’m working with is to have each subproject define its own build.gradle file for compiling itself, and then to dynamically build the root’s build.gradle file based on which projects are present. I’d like to inject dependency information then into the root project, and have gradle take care of building the subprojects in order.
root build.gradle template
subprojects {
task build { }
task dist(type: Zip) { task ->
from System.getProperty("user.dir")
doFirst {
new File("zips").mkdir()
archiveName = "zips/" + task.project.version + "_bin.zip"
}
}
subproject build.gradle template
version = "projA_v1.2.3"
build {
doLast {
// do actual build logic
}
}
dist {
includes = ["bin/projA_*"]
}
How do I define that the build task from projA depends on the build task of projB? I would like to be able to just call ‘gradle build dist’ and have everything build according to the dependencies, and then dist (in any order, doesnt matter). However, if I need to call the build and dist tasks separately as 2 commands, that is okay.
I’ve tried to follow the examples from chapter 56 and 59 of the User’s Guide, but I’m not entirely sure what’s happening, and the tasks end up executing in alphabetical order anyways:
project(":subdir/projA") {
dependencies {
build project(":subdir/projB")
}
}
I’m also open to other suggestions as to how to go about getting everything together. Thanks in advance
gradle version for good measure:
------------------------------------------------------------
Gradle 1.12
------------------------------------------------------------
Build time:
2014-04-29 09:24:31 UTC
Build number: none
Revision:
a831fa866d46cbee94e61a09af15f9dd95987421
Groovy:
1.8.6
Ant:
Apache Ant(TM) version 1.9.3 compiled on December 23 2013
Ivy:
2.2.0
JVM:
1.7.0_51 (Oracle Corporation 24.45-b08)
OS:
Linux 3.11.0-19-generic amd64