How to create a tar file using maven-assembly-plugin

38 views Asked by At

I have a multi module maven project. I have copied the generated jar of each module into an main module target/output folder. Now I want to tar this output folder contents but instead of generating 1 tar file for all the generated jar, my code is creating tar file of each jar.

POM.xml

 <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.6.1</version>
        <executions>
          <execution>
            <id>copy-artifact</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>${project.groupId}</groupId>
                  <artifactId>${project.artifactId}</artifactId>
                  <version>${project.version}</version>
                  <type>${project.packaging}</type>
                </artifactItem>
              </artifactItems>
              <outputDirectory>../target/output</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.5.3</version>
        <executions>
          <execution>
            <id>assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <appendAssemblyId>false</appendAssemblyId>
              <outputDirectory>../target/FinalOutput</outputDirectory>
              <descriptors>
                <descriptor>assembly/tar.xml</descriptor>
              </descriptors>
            </configuration>
          </execution>
        </executions>
      </plugin>

tar.xml

 <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>tar</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>../${project.build.directory}/output/</directory>
            <includes>
                <include>**</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

I want one tar file which will hold the all the jar present inside output folder. Output(Module1-1.0-SNAPSHOT.jar, Module2-1.0-SNAPSHOT.jar,Module3-1.0-SNAPSHOT.jar)

0

There are 0 answers