Extract one level of transitive dependency


(Ben Middleton) #1

I have a challenge. I have a maven pom which lists a set of ZIP artifacts - and this is listed as a dependency in my gradle project. i.e.

archives - Configuration for archive artifacts.
\--- com.domain:layout:1.0-SNAPSHOT
     +--- com.domain:artifact-a:1.0-SNAPSHOT:zip
          \--- com.domain:other-dependency-a:1.0-SNAPSHOT
     +--- com.domain:artifact-b:1.0-SNAPSHOT:zip
          \--- com.domain:other-dependency-b:1.0-SNAPSHOT

You’ll notice that each of the ZIP artifacts also has other transitive dependencies, which in turn may have others etc. Now I’m trying to extract each of the first-level zip artifacts to a local folder. So far I have this:

dependencies {
    archives ('com.domain:layout:1.0-SNAPSHOT') {
        transitive = true
    }
}

task extractDependencies(type: Copy) {
    inputs.files configurations.archives
    into "$buildDir/layout"
    from { configurations.archives.collect { zipTree(it) } }
}

The problem I have right now is that this will recurse down the tree, fetching every transitive dependency and extracting it as well. However, I’m only after the first-level transitive dependencies getting extracted (i.e. artifact-a and artifact-b). Is this possible? I cannot explicitly exclude the groupId or artifactId of the unwanted dependencies, as it’s a huge list. If I set transitive = false, then this won’t extract the first-level transitive dependencies.

I could, of course, define the dependencies directly in gradle, and disregard the layout pom - but this is managed by a different team, and will contain build-specific version numbers that they manage.

Thanks for any pointers.