1

I create a JAR containing the code from several projects with the maven-assembly-plugin's jar-with-dependencies descriptorRef as described here: Including dependencies in a jar with Maven.

But how do I get it to produce output file foo-1.0.jar instead of the ugly foo-1.0-SNAPSHOT-jar-with-dependencies.jar? I don't need the default JAR that doesn't contain other projects.

Community
  • 1
  • 1
Johannes Ernst
  • 3,072
  • 3
  • 42
  • 56

2 Answers2

3

In the maven-assembly-plugin you can add an optional parameter called appendAssemblyId (which is set to true by default) in the configuration tag of your assembly execution.
The use of this tag will generate two warnings indicating that you might override the main build of the artifact (done by the maven-jar-plugin).
If you don't want to override this jar with appendAssemblyId set to false, you can decide to build your assembly in another folder with the property outputDirectory.
Or the other solution if you are ok with the fact to have append something at the end of the name of your jar is to create your own assembly descriptor.

(for more information about the existing parameters or how to create your own assembly descriptor you can see the plugin documentation here : https://maven.apache.org/plugins/maven-assembly-plugin/assembly-mojo.html)

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.5.3</version>
  <executions>
    <execution>
      <id>jar-with-dependencies</id>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
      <configuration>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <appendAssemblyId>false</appendAssemblyId>
        <outputDirectory>${project.build.directory}/my-assembly/</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

Edit : I edited my answer in order to make it more complete.

Fabien
  • 859
  • 6
  • 15
  • This seems to produce the right result, but with several warnings in the process about replacing the main artifact (doesn't the with-dependencies-jar overwrite the previously generated regular one?), and "'appendAssemblyId' is set to false, and 'classifier' is missing." -- classifier seems deprecated though and setting it makes no difference. – Johannes Ernst Apr 20 '15 at 19:18
  • I think that the two warnings cannot be avoided. In my project I generate the different assemblies in specific directories (parameter **outputDirectory**) so they don't override the main jar which is produced by the maven-jar-plugin and I also have the them. I think they are displayed deliberately to make sure that you know what you are doing. (and by the way, the **classifier** parameter is **deprecated**...) – Fabien Apr 20 '15 at 19:43
1

Here's what I ended up doing. In my pom.xml:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.5.3</version>
    <executions>
        <execution>
            <id>all</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <descriptors>
            <descriptor>all.xml</descriptor>
        </descriptors> 
    </configuration>
</plugin>

I specify a home-grown assembly descriptor, which I get by copying the assembly file jar-with-dependencies.xml from https://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html into local file all.xml, changing id jar-with-dependencies to all. Voilà, now the generated filename is foo-1.0-SNAPSHOT-all.jar, which works for my purposes.

Fabien
  • 859
  • 6
  • 15
Johannes Ernst
  • 3,072
  • 3
  • 42
  • 56