Need a more "gradle way" to handle my downloaded zip full of jars

You’ve got a lot of the right ideas.

I’d try something like this:

apply plugin: "java"

configurations {

dependencies {
    zipped group: '', name: 'MyZipFullOfJars', version: '5.0.1', ext: 'zip'	
    compile files({ tasks.installDependencies.extractedJars })

task installDependencies(type: Sync) {
    def extractDir = "${buildDir}/my-libs"
    ext.extractedJars = fileTree(extractDir) {
        include "**/*.jar"
        builtBy "installDependencies"

    dependsOn configurations.zipped
    from { 
        configurations.zipped.collect { zipTree(it) }
    into extractDir

// just for checking that it worked
task printClasspath {
    dependsOn configurations.compile
    doLast {
        configurations.compile.each {
            println it

Key points

  • Keep your downloaded zip out of the configurations that java adds. This makes it easier to use later.
  • Use { closures } to delay some things (like getting the tasks before they’re defined)
  • Avoid resolving the dependencies in the configuration phase with closures again
  • Since you need to apply a filter to the outputs, it’s easier to add an extra property as a FileTree on installDependencies and use that for your dependencies.

If you needed something like installDependencies in multiple projects, it would be time to break out a custom task type.