How can I re-use the war source files from another subproject in my current subproj, thereby skipping war creation in the other project?

(ola.sundell) #1

How can I re-use the war source files from another project in my current, so I can skip packaging the actual war in the other project?

I’ll elaborate: I’m converting the 15k lines of pom.xml that we use to build our project here at and it’s fun but slightly daunting.

I have two kinds of modules in my Java project (I have other kinds as well, but these two are relevant for this question): * widgets (about 50), essentially a spring MVC controller with views as JSPs, tagfiles and configuration files, packaged as war files. * publications (three), true webapps

The publications depend on the widgets. They share some of them but not all. Certain widgets are only used in two publications, etc. When we’re using maven to build the publications we use maven-shade-plugin to concatenate certain configuration files from the widget dependencies, using both plain text and xml transformers. I’ve written a semi-ugly hack to do what the shade plugin does, including transformation. Naturally it requires, just as the maven plugin does, that I unpack the widget wras.

I specify my widget dependencies as project(path: ‘widget-foo’, configuration: ‘archives’) to make sure that I get the wars and the wars alone.

However, it’s quite time consuming to first pack the widgets as wars and then just moments later zipTree unpack them again. Of course I only have to package the widgets once, but unpacking them is still quite slow.

Is it possible, for instance, to ask the widget projects nicely for their war.source sets and then use that collection instead of having to unpack them? Would you recommend me going about this in an entirely different manner?

Thanks for a wonderful build automation tool, it sure blows maven out of the water! Ola Sundell

(Tye Howard) #2

Sounds like you want something like this :

allprojects {
        apply plugin: "java"
task copySources(type:Copy) {
        subprojects.each { sub ->
                from sub.compileJava.destinationDir
        into "output"
  subprojects { sub ->
        copySources.dependsOn sub.compileJava

(ola.sundell) #3

That’s a good idea, but I’m after the war files and not just the jar. I’ll probably be able to apply it to the war files as well, though. I’ll try it out!