Create dynamically task based on resolved configuration fails in composite build

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?

Hi, was wondering if you ever managed to solve this problem? I’m facing the same issue.
Thanks.

Sounds more like a use case for an artifact transform: Gradle User Manual: Version 7.0