Create dynamically task based on resolved configuration fails in composite build

(Matthieu Ghilain) #1

I am trying to extract content of a JAR published in another project.
I have created a special configuration ‘generateApis’ to list the artifacts I want to extract.

Based on this resolved configuration I create dynamically copy tasks as shown below.

configurations.generateApis.resolvedConfiguration.resolvedArtifacts.each {
    def moduleVersionIdentifier = it.moduleVersion.id
    if (moduleVersionIdentifier.group.startsWith("org.test")) {
        def apiJarPath = it.file
        String extractDependencyTaskName = "extract-dependency-${moduleVersionIdentifier.id.name}"
        println extractDependencyTaskName
        unpackApis.dependsOn(extractDependencyTaskName)
        project.tasks.create(name: extractDependencyTaskName, type: Copy.class) {
            from zipTree(apiJarPath)
            into unpackedApisDirectory
        }
    }
}

This fails in a composite build with the following error
Cannot expand ZIP ‘xxx.jar’ as it does not exist.

This however works perfectly when I build the two projects independently.

What did I miss?