Issue
On building my spring boot app using mvn clean package
, the final artifact that is getting built, myapp.jar, is not having the version number included in the jar name.
What change should i do to get the artifact verion number to be part of jar.
The relevant part of pom.xml is as below -
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycomp</groupId>
<artifactId>myapp</artifactId>
<version>2.6.0</version>
<name>myapp</name>
<description>
<![CDATA[]]>
</description>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<springboot.version>2.5.6</springboot.version>
</properties>
<dependencies>
<!-- Spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.12</version>
</dependency>
...
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.6.3</version>
</dependency>
</dependencies>
<build>
<finalName>gitlab-finder</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
</plugin>
</plugins>
</build>
</project>
Note: I created a new spring boot project using spring starter (through sts), and for this new project the jar has artifact version included in the jar name by default. So wondering if this a default feature why is this not the case for my project (by the way, i am maintainer of this project not the creator but i have to add this feature of including version number to jar name.)
Solution
You are overwriting the default behaviour of generating project names. This is because you define the finalName
tag.
From the docs:
finalName: This is the name of the bundled project when it is finally built (sans the file extension, for example: my-project-1.0.jar). It defaults to ${artifactId}-${version}.
In your case it is defined as <finalName>gitlab-finder</finalName>
which does not contain the version of the project. You either add ${version}
to it <finalName>gitlab-finder-${version}</finalName>
or remove the finalName
tag.
Answered By - Ervin Szilagyi
Answer Checked By - David Goodson (JavaFixing Volunteer)