Is it possible to override the default name of the jar file created running the assembly:single
goal? I want to add a jar with dependencies that has a non-standard name. I am using version 2.6 of the plugin.
Asked
Active
Viewed 1.6k times
21
-
Why not just rename the file with copy-rename-maven-plugin. It actually will give the same outcome. – Ironluca Feb 12 '22 at 17:42
2 Answers
44
Yes, you need to use the finalName
configuration attribute. Note that you probaby also want to remove the assembly id that is appended by default to the final name, with the help of the appendAssemblyId
attribute.
Sample configuration:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
...
<finalName>myFinalName</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>

Tunaki
- 132,869
- 46
- 340
- 423
-
2there is no "finalName" in the assembly plugin: http://maven.apache.org/plugins/maven-assembly-plugin/single-mojo.html – Jason Oct 17 '18 at 19:08
-
to @jason : there is no "finalname" field but it works... I do not know the magic involved... – Francois Marot Apr 02 '20 at 08:42
-
3There is indeed a `finalName` parameter in the _single_ goal. It is not generated in the documentation, and it's declared as "read only" : see [source code](https://github.com/apache/maven-assembly-plugin/blob/maven-assembly-plugin-3.3.0/src/main/java/org/apache/maven/plugins/assembly/mojos/AbstractAssemblyMojo.java#L144). So it should normally not be possible to set it in the configuration, but it's a side effect (or a bug) in Maven 3. See [MNG-5001](https://issues.apache.org/jira/browse/MNG-5001) or [MJAR-264](https://issues.apache.org/jira/browse/MJAR-264). – Guillaume Husta Apr 28 '21 at 10:14
5
The proper way to do this (as mentioned on Maven JIRA tracker) is to set the build.finalName
and not to use the readonly finalName
plugin property. Here is an example how to get rid of both the "jar-with-dependencies" and the version, which is very useful for creating a stable name and eliminating potentially confusing existence of 2 JARs for use in README instructions:
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
...
<configuration>
<appendAssemblyId>false</appendAssemblyId>
...
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

berezovskyi
- 3,133
- 2
- 25
- 30