我正在使用Maven Assembly插件来包装可分配的Zip Archive。但是,我想在我的最后一个档案中包括一个单独的组件,jar-with依赖性的结果。我怎样才能做到这一点?我意识到我可能只能手动包含罐子,但是如何确保我的自定义组装将在罐子组件之后运行?
您可以使用多模块项目为此:
parent
|- ...
|- jar-with-dependencies-module
|- final-zip-module
在jar-with-dependencies
模块中,您将" Uber-jar"组装为所有依赖项。POM中的构建配置应看起来像这样:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
在final-zip-module
中,您可以将jar-with-dependencies
添加为依赖项,并将其用于zip文件的汇编描述符。POM看起来像这样:
<project>
...
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>jar-with-dependencies-module</artifactId>
<version>1.0.0-SNAPSHOT</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
和组装描述符看起来像这样:
<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>final-assembly</id>
<formats>
<format>zip</format>
</formats>
<dependencySets>
<!-- Include the jar-with-dependencies -->
<dependencySet>
<includes>
<include>com.example:jar-with-dependencies-module:*:jar-with-dependencies</include>
</includes>
<useProjectArtifact>false</useProjectArtifact>
<!-- Don't use transitive dependencies since they are already included in the jar -->
<useTransitiveDependencies>false</useTransitiveDependencies>
</dependencySet>t>
</dependencySets>
</assembly>
由于对jar-with-dependency-module
的依赖性,Maven始终将构建Uber-Jar后构建final-zip-module
。