I’ve got a very simple multiproject build like below:
module1, which generates a public API jar and exposes it through “publicAPI” configuration:
configurations {
publicAPI
}
task generatePublicAPI(type: Jar) {
outputs.upToDateWhen { false }
baseName ‘public-api’
from sourceSets.main.output
}
artifacts {
publicAPI generatePublicAPI
}
module2, which uses the public API jar (by referencing ‘publicAPI’ configuration defined in module1) to generate a application jar:
configurations {
generateApplication
}
dependencies {
generateApplication project(path: ‘:module1’, configuration: ‘publicAPI’)
}
task jarApp(type: Jar) {
baseName ‘app’
from configurations.generateApplication.collect {
it.isDirectory() ? it : zipTree(it)
}
}
Now, when I execute 'gradle :module2:jarApp" task, I got the following error:
Cannot expand ZIP > ‘/home/picasso/Documents/GradlePlayground/module1/build/libs/public-api.jar’ > as it does not exist
and I can see that gradle was not trying to execute ‘generatePublicAPI’ of module1.
However, if I make “jarApp” task depends on “generatePublicAPI” task explicitly,
task jarApp(dependsOn: ‘module1:generatePublicAPI’, type: Jar) {…}
then everything’s fine.
BUT, wouldn’t this approach against one of the purpose of using dependency configuration so that I don’t have to worry about the details of how module1 is built, e.g. which task generates the jar and what artifacts it produces?
I thought gradle is able to work out the tasks it needs to execute by following along the “route” of the referenced dependency configuration. Also tried to add ‘evaluationDependsOn(’:module1’)’ to module2 but it didn’t solve the problem.
Am I missing something here so that “generatePublicAPI” task can be executed automatically without have to declare “dependsOn” explicitly for “createApp” task?