Delip Delip - 1 month ago 9x
Java Question

Building Maven fat jar conditionally

I followed the example in Building a fat jar using maven and now I can run the following to build/test and install my jars.

mvn clean compile install

now takes a lot longer because we are now building a fat jar. Is it possible to have two versions of install where one just builds jars without dependencies and the other does that and in addition builds the fat jar, like:

mvn clean compile install
mvn clean compile install-fatjar

I know
is not a valid phase but just want to give an idea of what I'm trying to accomplish, i.e. a conditional install where the fat jar is built only when an option is provided.


Create a profile for the fat jar and configure the maven assembly plugin to create the fat jar in this profile.

For example use this profile:


Then you can build it by activating the profile

mvn -P fatjar clean install

where fatjar is the profile id.

Multiple profiles can also be activated

mvn -P fatjar,release install