Assemble multiple Java Projects together


(Benjamin Rogge) #1

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) ?


(Gary Hale) #2

Something like this should work:

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

(Gary Hale) #3

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”.


(Benjamin Rogge) #4

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


(Gary Hale) #5

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

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