Ertan D.
Ertan D.

Reputation: 832

Gradle extract multiple dependencies each to a different directory

I'm trying to extract multiple dependencies into different directories. I tried the following.

configurations {
   cppDependencies
}

dependencies {
   cppDependencies 'com.group:artifact1:1.0"
   cppDependencies 'com.group:artifact2:1.0"
}

task extractDeps(type: Copy) {
    from {
        configurations.cppDependencies.collect {
            zipTree(it)
        }
    }
    into new File(buildDir, "DEP_DIR")
}

Obviously this just extracts artifact1 and artifact2 under the same DEP_DIR directory. But what I would actually want to achieve is extract them under DEP_DIR/artifact1 and DEP_DIR/artifact2 respectively.

I tried to put into new File(buildDir, "DEP_DIR/" + it.artifactId) under the zipTree command but it gives an error.

Is this possible?

Upvotes: 3

Views: 1928

Answers (2)

Christoph S
Christoph S

Reputation: 773

I came up with a simliar solution in kotlin:

dependencies {
    myExtraDependency("org:mydependency-arm64:1.0.0")
    myExtraDependency("org:mydependency-x64:1.0.0")

}

val unzipTask = tasks.register<Copy>("unzip") {
    myExtraDependency.resolvedConfiguration.resolvedArtifacts.forEach {
        from(zipTree(it.file))
        include("**/*.so")
        into ("$buildDir/unzipped")
    }
}

Upvotes: 0

Ertan D.
Ertan D.

Reputation: 832

I found a working solution.

Don't know if it's the best way, but this is what I came up with:

task extractDeps << {
    configurations.cppDependencies.resolvedConfiguration.resolvedArtifacts.each { artifact ->
        copy {
            from project.zipTree(artifact.getFile())
            into new File(project.buildDir, "DEP_DIR/" + artifact.name)
        }
    }
}

Upvotes: 3

Related Questions