我有3个模块链接到父项目。我需要创建一个包含所有这些项目的zip文件。我知道可以使用maven assembly插件完成。但是我应该在哪个pom.xml中使用它。有没有办法可以将资源从3个项目复制到1个公共文件夹中。有没有相同的例子。这是一个多模块构建
答案 0 :(得分:1)
出于这样的目的,最好的方法是在多模块构建中创建一个单独的模块,这会产生以下结构:
root (pom.xml)
+--- mod1 (pom.xml)
+--- mod2 (pom.xml)
+--- mod3 (pom.xml)
+--- mod-package (pom.xml)
mod-package的pom.xml如下所示:
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.soebes.packaging.test</groupId>
<artifactId>root</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<artifactId>mod-package</artifactId>
<packaging>pom</packaging>
<name>Packaging :: Mod Package</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptors>
<descriptor>pack.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>package-the-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
不要忘记位于mod-package / pack.xml中的pack.xml文件:
<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>pack</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<!-- Enable access to all projects in the current multimodule build! -->
<useAllReactorProjects>true</useAllReactorProjects>
<binaries>
<outputDirectory>modules/${artifactId}</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
</moduleSets>
</assembly>