Create JARs containing classes and resources from webapp using Gradle

I would like to create a jar from the contents of WAR using gradle. The result I want is very similar to what archiveClasses = true maven-war-plugin setting does.

I understand that the gradle war plugin does not seem to do this (like this stack question) .

Is there any way to do this manually? Tell me, by manipulating the gradle jar task to collect the necessary parts from the WEB-INF folder?

When I just use the default jar task, it does not get resources from the WEB-INF directory.

The reason I want to do this is because I modulated the WAR and the modules depend on the shared resources in the WAR (FreeMarker files in my case). I want to be able to test each module, depending on the JAR created from the WAR.

I understand that I could also create a β€œcommon” jar in which all resources are stored, and both the WAR and the module depend on it, but it would be more convenient to create a WAR JAR form in accordance with maven-war -plugin.

+7
java jar gradle war
source share
2 answers

So here is how I solved it (not sure if this is the best way):

jar { from ("${projectDir}/src/main/webapp/WEB-INF") { include('freemarker/**') } } 

I also found this alternative in the Gradle forums, but I could not collect the line resources.srcDir("src/main/webapp").exclude('images/') , but I really as an idea somehow just add to the resource resources directory default is jar. Change I think my first example above is as good as he is.

+3
source share

You can add this to include both src / main / resources and scr / main / webapp in the root of the created jar file:

 sourceSets { main { resources { srcDirs "src/main/resources", "src/main/webapp" } } } 
+1
source share

All Articles