The intersection of technology and leadership

Generating a single fat jar artifact from maven

When using the jar-with-dependencies descriptorRef for the maven-assembly-plugin, it creates two files by default, the normal default jar with any library dependencies excluded, and a second jar with all the libraries included appended with “jar-with-dependencies”. Since I find maven help guides unintuitive, it took a while before we found the appendAssemblyId option to turn it off. Here’s the snippet of the pom.xml to create just a single far jar.

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <appendAssemblyId>false</appendAssemblyId>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
  </configuration>
  <executions>
    <execution>
      <id>make-assembly</id>
      <phase>package</phase>
      <goals>
        <goal>assembly</goal>
      </goals>
    </execution>
  </executions>
</plugin>

5 Comments

  1. n0rad

    I was looking for that to !

    I tried your solution but it doesnt work for me
    maven tells me :

    ————————————————————————
    [ERROR] FATAL ERROR
    ————————————————————————
    [INFO] An invalid artifact was detected.

    This artifact might be in your project’s POM, or it might have been included transitively during the resolution process. Here is the information we do have for
    this artifact:

    o GroupID: test.test2
    o ArtifactID: myid
    o Version: 1.0-SNAPSHOT
    o Type: jar

    which is actually the project that i’m trying to package

    do you have an idee for that ?

  2. n0rad

    i missed some information :

    org.apache.maven.artifact.InvalidArtifactRTException: For artifact {test.test2:myid:1.0-SNAPSHOT:jar}: An attached artifact must have a different ID than its corresponding main artifact.

  3. Patrick

    I did a couple of searches, and here’s some links I found:

    http://www.mail-archive.com/users@maven.apache.org/msg74371.html
    http://maven.apache.org/ref/2.0.4/maven-project/xref/org/apache/maven/project/artifact/AttachedArtifact.html

    I think it’s saying that you probably have the goal for the plugin as attached instead of what I have above, assembly. I never tried that, so I have no idea if that works. It would also help to see your pom.xml.

    Please leave a comment if this worked for you.

  4. sunilkumar

    Hi,
    I also encountered the same problem as n0rad.

    i changed
    <appendAssemblyId>false</appendAssemblyId>

    to
    <appendAssemblyId>true</appendAssemblyId>

    now it works fine

    sunil

  5. Michael Krog

    Thank you..

    Saved my day!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2022 patkua@work

Theme by Anders NorenUp ↑