我有一个多模块 maven 项目,以及许多构建标准 jar 文件的代码模块,我有一个模块使用 maven-assembly-plugin 将测试工具构建为 zip 文件,另一个模块构建应用程序 rpm使用 rpm-maven-plugin。我想在 rpm 中包含测试工具 zip 文件。
目前我正在 rpm 模块中执行以下操作:
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>appn</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>test-harness</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<configuration>
:
<mapping>
<directory>/opt/app/installed/${rpmSoftwareName}-${project.version}/utils</directory>
<username>${rpmUsername}</username>
<groupname>${rpmGroupname}</groupname>
<filemode>0755</filemode>
<sources>
<source>
<location>${project.build.directory}/../../test-harness/target/test-harness-${project.version}-dist.zip</location>
</source>
</sources>
</mapping>
<mapping>
<directory>/opt/app/installed/${rpmSoftwareName}-${project.version}/lib</directory>
<username>${rpmUsername}</username>
<groupname>${rpmGroupname}</groupname>
<filemode>0755</filemode>
<dependency />
</mapping>
我遇到的问题是 rpm 的 lib 目录包含测试工具及其传递依赖项。如果我从 lib 映射中排除测试工具,我不会得到测试工具,但我确实得到了它的传递依赖项。如果我将测试线束作为依赖项删除,那么我必须依赖父 pom 中的模块顺序来确保首先构建测试线束,这似乎有点弱,因为依赖相对路径来包含测试线束在映射中......必须有更好的方法。
最好的办法是首先不要使用访问其他模块的相对路径(../target/ 等)。最好在 rpm 模块中使用依赖项。例如,将 zip 文件定义为具有适当分类器的依赖项。
<dependencies>
<dependency>
<groupId>project.com.domain</groupId>
<artifactId>test-harness</artifactId>
<version>${project.version}</version>
<classifier>dist</classifier>
<type>zip</type>
</dependency>
</dependencies>
之后你应该简单地将依赖添加到 rpm-configuration 中,如下所示:
<mapping>
<directory>/usr/local/lib</directory>
<filemode>750</filemode>
<username>dumper</username>
<groupname>dumpgroup</groupname>
<dependency>
<includes>
<include>...:test-harness:dist:zip:${project.version}</include>
<include>...</include>
</includes>
<excludes>
<exclude>...</exclude>
</excludes>
</dependency>
</mapping>
我不是 100% 确定哪个是包含的确切顺序(artifactId:classifier:type:version?)。