Project dependencies


(Michael Brand) #1

I have a project where we have one project that creates a war and a second project that adds it to a tar file. The tar subproject contains something like:

task makeTar(type: Tar) {

dependsOn(":warProject").war

… }

This works fine as long as the name of my tar subproject comes after the name of my war project (e.g. zTarProject and warProject). If the order of the names are reversed, though, the tar project won’t compile, complaining that “warProject” does not contain the property “war”.

I’ve played around with this all night, but I can’t figure out how to force the war project to be evaluated before the tar project, regardless of name. For now I’ve renamed the tar project, but I’d like to figure out how to set this up correctly.

Thanks.


(Peter Niederwieser) #2

You can just do ‘dependsOn(":warProject:war")’.


(Michael Brand) #3
dependsOn(":warProject:war")

worked. I’ve had more issues with closures, though. For instance, I tried to create a copySpec like this:

def myConfig = copySpec {
    from project(":warProject").war
}

but this gives me the same error. For now I’ve just copied the following code into each task:

doFirst {
    from project(":warProject").war
}

which works fine. But it seems there should be a better way than to duplicate lines in multiple tasks.


(Peter Niederwieser) #4

In general, it’s recommended not to refer directly to elements of other projects, because it leads to strong coupling and may require you to defer access until the other project’s build script has been evaluated. In this case, I’d probably use a project dependency rather than referring to the other project’s ‘war’ task. Another solution is deferring access with ‘from { project(":warProject").war }’.