Child project class files in WEB-INF classes instead as jars in WEB-INF/lib

(las) #1

I have a parent project and multiple child projects. I want a war to be generated with class files from a couple of child projects and jars in lib from a couple of child projects.How to achieve this?

(Benjamin Muschko) #2

I think you have three options here:

  1. You set up a dedicated subproject whose only purpose it is to generate the WAR file by applying the war plugin. Dependencies to other subprojects are declared via project dependencies which the plugin resolves at runtime and adds them to the WEB-INF/lib directory in the generated WAR file.
  2. You create a task of type War in one of the subprojects that should be responsible for the WAR file creation. Establish project dependencies as described in 1.
  3. Make the root project responsible for creating the WAR file. You’d set up a task of type War in the root project’s build.gradle and then ask for the runtime classpath of all subproject that should be included.

Option 1. is probably the easiest to achieve your goal.

(las) #3

I want the class files of sub-projects in war’s classes folder rather than as jar in war’s luv folder. Please advise.

(Benjamin Muschko) #4

I can’t think of any compelling reason for wanting to do but you can get the compiled class files from the main source set of each subproject via sourceSets.main.output.

(las) #5

There compelling reason is that some sub-projects are not really libraries and we don’t want them to be jars in war’s lib folder.

Can you please elaborate your solution?