[JAVA] What is Maven Assembly?

Encounter suddenly

I suddenly encountered it at work, so I will give a brief overview.

Reference information Mave Assembly Plugin Maven tips

What is Maven Assembly

Maven Assembly is a Maven plugin used when you want to create an archive file for distribution. It seems that the creation method that can be specified by default is divided into the following three.

Default assembly command

The execution command and the created file are as follows.

bin


$ mvn assembly:assembly -DdescriptorId=bin

$ ls target
...
hello-world-1.0-SNAPSHOT-bin.tar.bz2
hello-world-1.0-SNAPSHOT-bin.tar.gz
hello-world-1.0-SNAPSHOT-bin.zip

jar-with-dependencies


$ mvn assembly:assembly -DdescriptorId=jar-with-dependencies

$ ls target
...
hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar

src


$ mvn assembly:assembly -DdescriptorId=src

$ ls target
...
hello-world-1.0-SNAPSHOT-src.tar.bz2
hello-world-1.0-SNAPSHOT-src.tar.gz
hello-world-1.0-SNAPSHOT-src.zip

Run from pom.xml

That said, it's a hassle to type long commands every time, right? You can specify a default command such as bin for descriptorRef specified in pom.xml. In the sample below, the archive will be executed at the time of mvn package.

pom.xml


<project>
...
  <build>
    ...
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>bin</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase> <!--Run at mvn package-->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    ...
</project>

I want to create my own archive

Of course, you can also customize what you archive. In this case, you can create the archive settings in a separate xml file.

assembly.xml


<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd" >
  <id>make-assembly</id>
  <formats>
    <format>tar.gz</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>target</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>*.jar</include>
      </includes>
    </fileSet>
  </fileSets>
  <dependencySets>
    <dependencySet>
      <unpack>false</unpack>
      <scope>runtime</scope>
      <outputDirectory>/</outputDirectory>
    </dependencySet>
  </dependencySets>
</assembly>

Executing only the original assembly file is as follows. Note that it is Ddescriptor instead of DdescriptorId. Also, in the case of independent execution, an error will occur if the assembly plugin is described in pom.xml, so if you want to try only this, comment out the pom.xml side.

$ mvn assembly:assembly -Ddescriptor=assembly/assembly.xml

If you want to execute it as an extension of pom.xml instead of executing this command, you can use it by specifying the file path in descriptor in configuration below.

pom.xml


...
<configuration>
  <descriptors>
    <descriptor>src/assembly/src.xml</descriptor>
  </descriptors>
</configuration>
...

Finally

If you want to know more details, please refer to the official website that I posted first for various information. Maven can also be used in Kotlin, so maybe there are still more uses?

In addition, when trying Maven Assembly this time, I used the Maven Example Project of Kotlin of JetBrains below. Not only Maven but also gradle version etc., so please have a look. Kotlin hello-world example with maven

Recommended Posts

What is Maven Assembly?
What is maven?
What is Docker?
What is null? ]
What is java
What is Keycloak
What is Jackson?
What is Docker
What is self
What is Jenkins
What is ArgumentMatcher?
What is IM-Juggling?
What is params
What is SLF4J?
What is Facade? ??
What is Java <>?
What is Gradle?
What is POJO
What is Java
What is centOS
What is RubyGem?
What is programming?
What is before_action?
What is Docker
What is Byte?
What is Tomcat
What is `docker-compose up`?
What is a constructor?
What is vue cli
What is an interface?
What is Ruby's self?
What is hard coding?
What is a stream
What is Ruby's attr_accessor?
What is Java Encapsulation?
What is permission denied?
What is instance control?
What is an initializer?
What is Spring Tools 4
What is an operator?
What is object orientation?
What is Guava's @VisibleForTesting?
What is MVC model?
What is an annotation?
What is Java technology?
What is Java API-java
What is @ (instance variable)?
What is Gradle's Artifact?
What is JPA Auditing?
[Swift] What is dismiss?
[Java] What is flatMap?
What is a Servlet?
What is web development?
[Java] What is JavaBeans?
[Android] What is Context? ??
[Java] What is ArrayList?
[Ruby] What is true?
What is object-oriented after all?
Maven default JDK version is 1.5
What is HttpSession session = request.getSession ();
What is Java Assertion? Summary.