I suddenly encountered it at work, so I will give a brief overview.
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.
bin Create an archive for binary distribution (includes project artifacts, READMEs, license files) Dependent libraries are not included
jar-with-dependencies Create a Jar file that summarizes the project and dependent libraries
src Create an archive for source distribution
The execution command and the created file are as follows.
$ 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
$ mvn assembly:assembly -DdescriptorId=jar-with-dependencies $ ls target ... hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar
$ 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
That said, it's a hassle to type long commands every time, right?
You can specify a default command such as
descriptorRef specified in pom.xml.
In the sample below, the archive will be executed at the time of
<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>
Of course, you can also customize what you archive. In this case, you can create the archive settings in a separate xml file.
<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
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
... <configuration> <descriptors> <descriptor>src/assembly/src.xml</descriptor> </descriptors> </configuration> ...
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