War task should allow bundling classes into jar

Currently the WAR task puts the compiled java classes under WEB-INF/classes. Instead I would like them to get bundled into a JAR and placed in WEB-INF/lib.

This would be analogous to Maven’s archiveClasses=true setting:

https://maven.apache.org/plugins/maven-war-plugin/faq.html#attached

1 Like

You are correct. It’s not a built-in feature of the WAR plugin. What’s the benefit of doing that from your perspective? If the main purpose is to reuse the classes as bundled JAR file somewhere else, it’s really easy to write your own task of type ‘Jar’ to achieve that.

You can configure your ‘war’ task to get this behavior.

war {

classpath = classpath - sourceSets.main.output

from (jar) {

into ‘WEB-INF/lib’

}

}

One use case I’ve seen is allowing the ability to easily override classpath resources in the jar by putting them in WEB-INF/classes. Typically this is the case when the war you are building is primarily going to be used as an underlay.

Thanks Mark. Works like a charm.