有四种预定义的描述符格式可供重用,封装在 Assembly Plugin 中。他们的descriptorIds是:
使用bin作为您的程序集插件配置的descriptorRef ,以创建项目的二进制分发存档。这个内置描述符生成一个带有分类器bin的程序集,分为三种存档格式:tar.gz、tar.bz2 和 zip。
组装的存档包含通过运行mvn package生成的二进制 JAR以及项目根目录中可用的任何 README、LICENSE 和 NOTICE 文件。
下面是bin描述符格式:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>bin</id>
<formats>
<format>tar.gz</format>
<format>tar.bz2</format>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/site</directory>
<outputDirectory>docs</outputDirectory>
</fileSet>
</fileSets>
</assembly>
使用jar-with-dependencies作为您的程序集插件配置的descriptorRef ,以创建一个包含项目二进制输出的JAR,以及解压后的依赖项。此内置描述符使用 JAR 归档格式生成带有分类器jar-with-dependencies的程序集。
请注意,jar-with-dependencies仅提供对 uber-jars 的基本支持。如需更多控制,请使用Maven Shade Plugin。
下面是jar-with-dependencies描述符格式:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<!-- TODO: a jarjar format would be better -->
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
在您的程序集插件配置中使用src作为descriptorRef来为您的项目创建源档案。存档将包含您项目的/src目录结构的内容,供您的用户参考。src描述符 ID 生成带有分类器src的程序集存档,分为三种格式:tar.gz、tar.bz2 和 zip。
以下是src描述符格式:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>src</id>
<formats>
<format>tar.gz</format>
<format>tar.bz2</format>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
<include>pom.xml</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src</directory>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>
在您的程序集插件配置中使用项目 <descriptorRef>将生成一个包含整个项目的程序集,减去/target目录中的任何构建输出。生成的程序集应该允许您的用户使用 Maven、Ant 或您在项目的正常 SCM 工作目录中配置的任何构建系统来构建您的项目。它使用分类器项目以三种归档格式生成程序集:tar.gz、tar.bz2 和 zip。
以下是项目descriptorRef的程序集描述符:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>project</id>
<formats>
<format>tar.gz</format>
<format>tar.bz2</format>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory></outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<excludes>
<exclude>**/*.log</exclude>
<exclude>**/${project.build.directory}/**</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>