93

This is how I configured maven-assembly-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <finalName>myapp</finalName>
        <archive>
            <manifest>
                <mainClass>com.myapp.Main</mainClass>
            </manifest>
        </archive>
        <!--
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        -->
    </configuration>
</plugin>

and I expect the final jar file should be myapp.jar but it ends up with myapp-jar-with-dependencies.jar

Can you tell me how to configure to exclude "jar-with-dependencies" out of the final name?

pbaris
  • 4,525
  • 5
  • 37
  • 61
Truong Ha
  • 10,468
  • 11
  • 40
  • 45

1 Answers1

223

You can specify the finalName property to give the jar the name you want, and specify that appendAssemblyId should be false to avoid the jar-with-dependencies suffix. The configuration below will output a jar called test.jar

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <finalName>test</finalName>
                <archive>
                    <manifest>
                        <mainClass>com.myapp.Main</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
               <appendAssemblyId>false</appendAssemblyId>
            </configuration>
         </plugin>
Matias Elorriaga
  • 8,880
  • 5
  • 40
  • 58
sasankad
  • 3,543
  • 3
  • 24
  • 31
  • 10
    you also should uncomment `` thing, otherwise you'll get something like that: `[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4:attached (default) on project ...: Error reading assemblies: No assembly descriptors found.` – tsayen Aug 18 '16 at 09:33
  • 9
    Excellent `false` this line is necessary . – GOXR3PLUS Oct 31 '17 at 22:04
  • The tag "finalName" is not in assembly plugin v3.x – James Selvakumar Sep 27 '18 at 08:25
  • 2
    But that produces a `[WARNING] Configuration options: 'appendAssemblyId' is set to false, and 'classifier' is missing` – isapir Nov 29 '18 at 19:42
  • @isapir, I googled for a solution and it appears that this _works as documented_. See https://issues.apache.org/jira/browse/MASSEMBLY-824. It also referenced http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_assembly, where the id field says *Sets the id of this assembly. This is a symbolic name for a particular assembly of files from this project. Also, aside from being used to distinctly name the assembled package by attaching its value to the generated archive, the id is used as your artifact's classifier when deploying*. I still don't fully understand it. – PatS Apr 26 '19 at 17:07
  • 1
    Here is the actual _works as documented_ change. http://svn.apache.org/viewvc?view=revision&revision=1754566, it is referenced in https://issues.apache.org/jira/browse/MASSEMBLY-824 (link in my previous comment). – PatS Apr 26 '19 at 17:13
  • 1
    The described solution doesn't work for me with plugin v2.4 nor v2.2.2, for example. Tested with Maven 3.3.9. Moreover, it seems like the possibility of setting name of the resultant assembly artifact was removed in 3.x altogether - see [How to set final jar name with maven-assembly-plugin version 3](https://stackoverflow.com/questions/45101044/how-to-set-final-jar-name-with-maven-assembly-plugin-version-3). Altogether, this maven plugin is very confusing. – Petr Bodnár Nov 12 '19 at 17:01