Search code examples
mavenmaven-assembly-plugin

Maven assembly put jar-with-dependencies into tar.gz package


I am using maven assembly plugin to package a fat jar, and then I want to put the fat jar into the tar.gz package, which is also generated by mvn-assembly plugin.
The thing is assembly will not put the fat jar into the tar file, but put the small jar,which only contains code and no dependencies in it.
Here's my pom file:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId>
            <version>2.5.5</version>
            <configuration>
                <descriptor>src/main/resources-local/assembly.xml</descriptor>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>my.App</mainClass>
                    </manifest>
                </archive>
                <outputDirectory>output</outputDirectory>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

And assembly.xml:

<id>release</id>
<formats>
    <format>tar.gz</format>
</formats>

<dependencySets>
    <dependencySet>
        <outputDirectory>/lib</outputDirectory>
        <includes>
            <include>*:project:*:*</include>
        </includes>
        <useProjectArtifact>true</useProjectArtifact>
        <unpack>false</unpack>
        <scope>runtime</scope>
    </dependencySet>
</dependencySets>

Solution

  • solved this

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
            <version>2.5.5</version>
            <executions>
                    <execution>
                        <id>make-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                            <finalName>project-${version}</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                    </execution>
                    <execution>
                        <id>make-tar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptor>src/main/resources-local/assembly.xml</descriptor>
                            <archive>
                                <manifest>
                                    <mainClass>my.App</mainClass>
                                </manifest>
                            </archive>
                            <outputDirectory>output</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </executions>
        </plugin>