【问题标题】:maven include assembly from another module into rpmmaven 将来自另一个模块的程序集包含到 rpm 中
【发布时间】:2012-04-24 13:32:55
【问题描述】:

我有一个多模块 maven 项目,以及许多构建标准 jar 文件的代码模块,我有一个模块使用 maven-assembly-plugin 将测试工具构建为 zip 文件,另一个模块构建使用 rpm-maven-plugin 的应用程序 rpm。我想在 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 目录包含测试工具及其传递依赖项。如果我从库映射中排除测试工具,我不会得到测试工具,但我确实得到了它的传递依赖。如果我将测试工具作为依赖项删除,那么我必须依赖父 pom 中的模块顺序来确保首先构建测试工具,这似乎有点弱,因为依赖相对路径来包含测试工具在映射中...一定有更好的方法。

【问题讨论】:

    标签: maven


    【解决方案1】:

    最好的办法是首先不要使用访问其他模块的相对路径(../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 配置中:

    <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?)。

    【讨论】:

    • 将测试工具添加为依赖项(即使使用分类器和类型)仍然会导致它及其传递依赖项包含在 rpm lib 目录中。在 lib 目录映射中排除测试工具只是排除了测试工具,但仍保留其传递依赖关系 - 但我认为这是正确的方向
    • 在依赖项区域添加排除项。这应该可以解决问题。
    猜你喜欢
    • 1970-01-01
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    • 2016-12-29
    • 2021-05-11
    • 2011-06-02
    相关资源
    最近更新 更多