What is the best way to create a distribution that contains multiple sources?

I am trying to use the distribution plugin as a replacement for the Maven assembly plugin. The assembly descriptor has multiple file sets that are assembled into different sub-directories in the resulting .zip.

It appears that this is not trivial with Gradle. For instance, if I want to place all of my .ear/.war files from other projects into separate directories, I might try something like this.

apply plugin: 'distribution'
  configurations {
 warFiles
 earFiles
}
  dependencies {
 warFiles project(path: ':installer', configuration: 'archives')
 warFiles project(path: ':job-consumer-app', configuration: 'archives')
 warFiles project(path: ':file-watcher-app', configuration: 'archives')
 earFiles project(path: ':ear', configuration: 'archives')
}
  distributions {
 main {
  baseName = 'someName'
  contents {
   from project.getConfigurations().getByName('warFiles')
   into 'WarFiles'
  }
    contents {
   from project.getConfigurations().getByName('earFiles')
   into 'Ear'
  }
 }

However, this ends up placing everything into a single directory ‘Ear’ rather than two separate directories ‘Ear’ and ‘War’. It appears that the contents property on the distribution object is a single CopySpec rather than a set of CopySpecs.

What is the best way to accomplish this?

distributions {
    main {
        baseName = "someName"
        contents {
            into("WarFiles") {
                from project.configurations.warFiles
            }
            into("Ear") {
                from project.configurations.earFiles
            }
        }
    }
}