Cross-project configuration dependency isn't working as expected

(Scott Palmer) #1

I have a complex multi-project build where one of the subprojects (ProjectA) builds a distribution Zip and another project (Installer) depends on it. A copy task in the Installer project complains that it can’t copy from the Zip because it doest exist. Sure enough :ProjectA:zipDist didn’t run yet.

ProjectA’s build.gradle contains:

configurations { distObfuscated }

task zipDist(type: Zip) { ... }

archives {
	distObfuscated zipDist

In the Installer build.gradle has:

configurations {
dependencies {
	projectADist project(path: ':ProjectA', configuration: 'distObfuscated')
	projectB project(path: ':ProjectB',transitive: false)

task prepareImage(type: Copy) {
	into "$buildDir/image"
	from (configurations.projectADist.findAll{'.zip') }.collect{zipTree(it)})
	from (configurations.projectB)

I thought that by depending on the distObfuscated configuration, that the zipDist task would automatically run. Doesn’t Gradle know, because of how the archives for ProjectA are declared, that the files in the distObfuscated configuration are ‘builtBy’ the zipDist task?

Is that not how it is supposed to work?

(Stefan Oehme) #2

Yes, Gradle knows that, but by doing this:

You are converting the configuration (which knows where it comes from) to a plain old Iterable<File>, which has no such information.

You’ll have to help Gradle understand your input relationship in that case: prepareImage.inputs.files configurations.projectADist

(Scott Palmer) #3

Ah, I see it now. Thanks!