Assemble multiple Java Projects together

We have multiple java projects, each producing a jar build by gradle. Now we would like to assemble them all together to form our shippable product (which means opy all jars and their dependencies to a certain place) How would we go about and define an assemble task for our root project (the Gradle way) ?

Something like this should work:

task assembleDist(type: Copy) {
  subprojects.each { subProject ->
  from subProject.jar
  from subProject.configurations.runtime

Another way to approach this would be to create a configuration (say “fulldist”) with all of the subprojects you want to include as dependencies, then just use “from configurations.fulldist”.

Thanks a lot. And how would you do it, if you need only specific projects. Can you access them somehow by name?

Lots of different ways you could approach that, but subprojects is a collection, so you could do something like this:

subprojects.findAll { =~ /regex/ }.each { subProject ->