Include Maven profile name in assembly-assembly (with dependencies) jar

I use maven-assembly-plugin to create an executable monolithic jar with dependencies. I also use resource filtering to set some custom strip-related (dev, stage, prod, etc.) properties.

How to make finalName of jar include strip name (dev, stage, prod, etc.)?

I would like the following mvn commands to produce banners that look something like this:

  • mvn clean install -P DEV โ†’ ws-client-DEV.jar
  • mvn clean install -P STAGE โ†’ ws-client-STAGE.jar
  • mvn clean install -P PROD โ†’ ws-client-PROD.jar

Is there a maven property somewhere I cannot find? I would like to avoid using a redundant command line argument if possible (ie - "mvn clean install -P DEV -Dlane = DEV").

Here is my build plugin configuration:

<plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2.2</version> <executions> <execution> <id>jar-with-dependencies</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <finalName>ws-client</finalName> <appendAssemblyId>false</appendAssemblyId> <archive> <manifest> <mainClass>Example</mainClass> </manifest> </archive> </configuration> </plugin> 
+6
source share
2 answers

Like Bhaskar, but slightly modified.

After the <build> tag, add

 <finalName>${project.artifactId}-${lane}</finalName> 

You can set the value of the strip as a property in the profile.

 <profiles> <profile> <id>DEV</id> <properties> <lane>DEV</lane> </properties> </profile> </profiles> 

Then build as you say: mvn ... -P DEV (e.g. mvn clean install -P DEV)

+9
source

After the <build> tag, add

 <finalName>${project.artifactId}-${lane}</finalName> 

And set the env variable "lane" to the profile name, for example.

mvn -P DEV -Dlane = DEV etc.

Or you can be a little more creative and discover an active profile identifier as described here Maven - Can I refer to a profile identifier in a profile definition?

EDIT ------

If you want to avoid redundant arguments.

Why not invoke the appropriate profiles using env. property.

so on the command line

 mvn -Dlane=DEV|STAGE|PROD 

and in pom

 <profile> <id>DEV</id> <activation> <property> <name>lane</name> <value>DEV</value> </property> </activation> <build> // rest of the profile </profile> 

And the same for STAGE and PROD profiles.

+2
source

Source: https://habr.com/ru/post/914650/


All Articles