Nandor Nandor - 3 months ago 18
Java Question

Maven assembly plugin creates two unexpected jars

I want to use maven-assembly-plugin to pack external dependencies into the application's jar file. When I call mvn install it creates two jar files, one with and one without the dependencies. (appname-version.jar and appname-version-jar-with-dependencies.jar)

My question is that why it creates two jar files?

Here is the plugin: (im not using any other plugin at the moment)

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.coolapp.mainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>


Thank you!

Answer

You need to update the maven-jar-plugin to avoid creating the default jar. This is done by adding <phase>none</phase> to its execution details:

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.0.2</version>
    <executions>
      <execution>
         <id>default-jar</id>
         <phase>none</phase>
      </execution>
    </executions>
</plugin>

All the resources/classes are still moved to the target folder, to the maven-assembly can build itself correctly.

Comments