How do I include the artifact of a configuration inside a distribution zip?

I’ve got the following gradle subproject file (gradle 1.5):

apply plugin: 'java'
apply plugin: 'distribution'
  //-----------------------------------------------------------------------------
// source sets and configurations
//-----------------------------------------------------------------------------
  sourceSets {
    main {
        java {
            srcDirs = []
        }
        resources {
            srcDirs = []
        }
    }
      common {
        java {
            srcDirs = ['src']
            exclude 'com/relay/server'
        }
    }
      server {
        java {
            srcDirs = ['src']
            exclude 'com/relay/core'
            exclude 'com/relay/Constants*'
        }
        resources {
            srcDirs = ["${rootDir}/resource/common"]
            include '*.properties'
        }
    }
}
  configurations {
    commonCompile {
        extendsFrom configurations.compile
    }
      serverCompile {
        extendsFrom configurations.compile
    }
 }
  //-----------------------------------------------------------------------------
// dependencies
//-----------------------------------------------------------------------------
  dependencies {
    compile project(':src/lib')
    serverCompile project(path:':src/relay', configuration:'commonCompile')
  }
  //-----------------------------------------------------------------------------
// output (distributions and artifacts)
//-----------------------------------------------------------------------------
  task commonJar(type: Jar, dependsOn: commonClasses) {
    baseName 'relay-common'
      from sourceSets.common.output
}
  task serverJar(type: Jar, dependsOn: serverClasses) {
    baseName 'relay-server'
      from sourceSets.server.output
    manifest {
        attributes(
            'Main-Class': 'com.relay.server.RelayServer'
        )
    }
}
  artifacts {
    commonCompile commonJar
    serverCompile serverJar
}
  distributions {
    main {
        baseName = 'relay-server'
          contents {
            from configurations.serverRuntime
            from configurations.serverRuntime.allArtifacts
        }
    }
}
  distZip {
    dependsOn serverJar
}
  distTar {
    enabled = false
}
  installDist {
    enabled = false
}

While in this block:

distributions {
    main {
        baseName = 'relay-server'
          contents {
            from configurations.serverRuntime
            from configurations.serverRuntime.allArtifacts
        }
    }
}

configurations.serverRuntime gets all the jars/dependencies, configurations.serverRuntime.allArtifacts doesn’t seem to work (i.e. the distZip doesn’t contain relay-server.jar. Any idea why?

Don’t you get a deprecation warning for ‘from configurations.serverRuntime.allArtifacts’? Try ‘from configurations.serverRuntime.allArtifacts.files’ or ‘from serverJar’.

Yes, I do, but I didn’t realize that the deprecation meant that it would be non-functional - I should have paid closer attention!

So, this is what worked for me:

from configurations.serverRuntime.allArtifacts.files

Thanks Peter!

In Gradle, a deprecation warning is quite often a sign of a mistake. This is because we are deprecating APIs that have proven to be frequent causes of mistakes. For example, ‘CopySpec.from’ used to accept any type of object, and if it didn’t know how to turn it into a file (or collection of files), it would just call ‘toString()’ and interpret the result as a file path. Since this proved to be more harmful than useful, passing an arbitrary object to ‘from’ has been deprecated.