This is an old post but I think both answers are not accurate and not 100% correct.
The fact is that uber JAR must contain all runtime and provided dependencies. But the first issue starts from here.
Usually, dependencies contain their own MANIFEST.MF
files and if you assembly them into a JAR with the examples above then you will get a WARNING
during the Maven build about the fact that you overwrite them because JAR can only have one MANIFEST file. This is not good. So please do not put dependencies under the same directory.
The second issue is related to the following two warnings:
[WARNING] Configuration options: 'appendAssemblyId' is set to false, and 'classifier' is missing. Instead of attaching the assembly file: [...]/target/....jar, it will become the file for main project artifact.
NOTE: If multiple descriptors or descriptor-formats are provided for this project, the value of this file will be non-deterministic!
[WARNING] Replacing pre-existing project main-artifact file: [...]/target/....jar with assembly file: [...]/target/....jar
The reason why you get this because you build a new JAR with the assembly-plugin but the classifier of your assembled JAR is not specified.
A Maven project that is not of type pom produces by default as the main artifact. This artifact is the result of maven packaging (JAR, WAR, or EAR). This artifact is attached to your project and used by Maven while installing, deploying, or releasing your project with mvn install
, mvn deploy
. Of course, you can generate different files under the target folder, but your main artifact is still the same.
And the JAR that you are building with the assembly plugin is in conflict with your default artifact. So I highly recommend you to NOT use this:
<appendAssemblyId>false</appendAssemblyId>
The assembly ID is the classifies of your uber JAR so, please set the property above to TRUE or ignore it completely because its default value is TRUE.
The default naming convention for artifacts is this: artifactId-version(-classifier).type
You can find a complete example below.
pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven.assembly.plugin.version}</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<finalName>${project.artifactId}-aa-${project.version}</finalName>
<descriptors>
<descriptor>${basedir}/src/main/resources/assembly.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>x.y.z.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Assembly plugin configuration:
<assembly>
<id>with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>provided</scope>
</dependencySet>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
This is how the assembled JAR is named: <project-name>-1.0-with-dependencies.jar
Hope that it helps you to build your perfect uber JAR.