3

This is follow up based on this answer.

I have a structure that looks like

$ ls service/target/
classes             lib             maven-status            surefire-reports
classes.-1194128992.timestamp   maven-archiver          service-1.0-SNAPSHOT.jar

and with-in that lib looks like

$ ls service/target/lib/
activation-1.1.jar              akka-http-spray-json-experimental_2.11-1.0.jar  mail-1.4.7.jar                  scala-reflect-2.11.2.jar
akka-actor_2.11-2.3.12.jar          akka-parsing-experimental_2.11-1.0.jar      manager-1.0-SNAPSHOT.jar            scala-xml_2.11-1.0.2.jar
akka-http-core-experimental_2.11-1.0.jar    akka-stream-experimental_2.11-1.0.jar       reactive-streams-1.0.0.jar          scalatest_2.11-2.2.5.jar
akka-http-experimental_2.11-1.0.jar     config-1.2.1.jar

As part of mvn clean install, I want to bundle my-deployment-artifact which should look contain

service-1.0-SNAPSHOT.jar
lib/* (all the jars here)

How do I create this as a tar or .tar.gz and produce with mvn clean install?

Community
  • 1
  • 1
daydreamer
  • 87,243
  • 191
  • 450
  • 722

1 Answers1

3

You can use maven-assembly-plugin to do that task.

Create an assembly definition file in src/assembly/distribution.xml

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    <id>distribution</id>
    <formats>
        <format>tar</format>
    </formats>
    <files>
        <file>
            <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
        </file>
    </files>
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/lib</directory>
            <outputDirectory>lib</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

In pom.xml file, add plugin declare, execution phase and goal for it.

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.5.5</version>
    <configuration>
        <descriptor>${project.basedir}/src/assembly/distribution.xml</descriptor>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

More format file or customize of maven-assembly-plugin can be found here: https://maven.apache.org/plugins/maven-assembly-plugin/

mquan86
  • 86
  • 4