Maven – Only create executable jar-with-dependencies in Maven

jarmaven

In my pom.xml I use the maven-assembly-plugin to create an executable jar-with-dependencies when running "mvn clean install".
Now it first creates the non-executable "name-version.jar" and after that the "name-version-jar-with-dependencies.jar".

Can I configure the pom.xml somehow, so that it doesn't create the non-executable JAR file?

At the moment I use <appendAssemblyId>false</appendAssemblyId> so it just overwrites the first file…

Also I get several "… already added, skipping" messages. Can I somehow prevent them?

This is the maven-assembly-plugin definition in my pom.xml:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2-beta-5</version>
    <configuration>
        <appendAssemblyId>false</appendAssemblyId>
        <archive>
            <manifest>
                <mainClass>my.main.class</mainClass>
            </manifest>
        </archive>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Best Answer

I got it to work using the maven-jar-plugin and the single goal of maven-assembly-plugin like this

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <finalName>finalName</finalName>
                <archive>
                    <manifest>
                        <mainClass>
                            mainClass
                        </mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </execution>
    </executions>
</plugin>

Anyway the most important thing is to tell maven not to generate the default jar using this configuration of the maven-jar-plugin

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