简体   繁体   中英

Custom versioning of Jar in maven pom.xml

I want to create versioning structure folder for maven project in .m2

Below changes I have made in pom.xml

<modelVersion>4.0.0</modelVersion>
<groupId>com.XXXXXX.cm</groupId>
<artifactId>state-node</artifactId>
<version>1.5.0/1.0</version>
<packaging>jar</packaging>
<name>state-node</name>

<build>
    <finalName>${project.artifactId}</finalName>
</build

Output:

.m2\repository\com\XXXXXX\cm\state-node\1.5.0\1.0\state-node-1.5.0\1.0.jar

Expected Output :

 .m2\repository\com\XXXXXX\cm\state-node\1.5.0\1.0\state-node-1.5.0.jar

1.5.0 is my dependency version and 1.0 is my project version. Project requirement is, If I use dependency (1.5.0) to build same project then jar folder structure should be in my .m2 folder 1.5.0\\1.0\\state-node-1.5.0.jar, If We do some modification in my project with same version of dependency then jar folder structure should be in .m2 folder 1.5.0\\2.0\\state-node-1.5.0.jar We will manually update version 1.0 to 2.0 in pom.xml in case we do some modification

How I can achieve this.

Ideally you should not use version like this. You should use like <version>1.5.0</version>

But if you still want to use the same and just want to modify the jar file name than you can use below solution:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <finalName>myJar</finalName>                   
    </configuration>
</plugin>

Or For Maven >= 3

<build> <finalName>WhatEverYouLikey</finalName> </build>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM