【问题标题】:maven rpm plugin needs full path to source location in multi module projectmaven rpm插件需要多模块项目中源位置的完整路径
【发布时间】:2012-07-12 16:08:41
【问题描述】:

我有一个多模块 Maven 项目。我从父 pom 调用 RPM 插件,但与 maven 程序集插件不同,我需要提供我希望打包到 RPM 指定目录的源的完整路径。

例如,除非我指定完整路径,否则以下位置路径将不起作用:

<sources>
  <source>
    <location>/src/main/config</location>
  </source>
</sources> 

正则表达式和通配符也不起作用。

有什么建议吗?

谢谢

【问题讨论】:

    标签: maven plugins rpm


    【解决方案1】:

    源参数的documentation表示:

    如果路径以 / 开头,则认为它是相对于 项目的基本目录。

    因此,如果您从位置参数中删除前导 /,它应该可以工作。

    -- 更新--

    我用这个简单的多模块项目做了一个小测试:

    rpm-test
    |-- module1
    |   |-- pom.xml
    |   |-- src
    |       |-- main
    |       |   |-- config
    |       |   |   |-- mod1-file1.conf
    |       |   |   |-- mod1-file2.conf
    |-- module2
    |   |-- pom.xml
    |   |-- src
    |       |-- main
    |       |   |-- config
    |       |   |   |-- mod2-file1.conf
    |       |   |   |-- mod2-file2.conf
    |-- pom.xml
    

    parent POM中rpm-maven-plugin的配置如下:

    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>rpm-maven-plugin</artifactId>
      <version>2.1-alpha-1</version>
      <inherited>false</inherited>
      <configuration>
        <copyright>2012, Me</copyright>
        <group>mygroup</group>
        <mappings>
          <!-- Option 1: Use the base directory and includes -->
          <mapping>
            <directory>/usr/local</directory>
            <sources>
              <source>
                <location>${project.basedir}</location>
                <includes>
                  <include>**/src/main/config/**</include>
                </includes>
              </source>
            </sources>
          </mapping>
    
          <!-- Option 2: List each module separatly -->
          <mapping>
            <directory>/tmp</directory>
            <sources>
              <source>
                <location>${project.basedir}/module1/src/main/config</location>
              </source>
              <source>
                <location>${project.basedir}/module2/src/main/config</location>
              </source>
            </sources>
          </mapping>
        </mappings>
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>rpm</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    

    当我使用rpm -qpl 查询生成的 RPM 的内容时,我得到以下结果:

    /tmp
    /tmp/mod1-file1.conf
    /tmp/mod1-file2.conf
    /tmp/mod2-file1.conf
    /tmp/mod2-file2.conf
    /usr/local/module1/src/main/config/mod1-file1.conf
    /usr/local/module1/src/main/config/mod1-file2.conf
    /usr/local/module2/src/main/config/mod2-file1.conf
    /usr/local/module2/src/main/config/mod2-file2.conf
    

    【讨论】:

    • 是的,您是正确的,但是该路径存在于许多子模块中。它们都在 src/main/config 下放置了配置文件,我需要访问它们,以便将它们打包到 conf RPM 位置。由于我是从父模块运行的,因此 basedir 路径确实指向子模块 src/main/config 目录。
    • 最简单的解决方案是使用 ${project.basedir}/src/main/config。
    • 当 rpm 插件只在父模块中运行时(您是否配置了 &lt;inherited&gt;false&lt;/inherited&gt;?),在您的配置中使用 &lt;includes&gt; 可能是一个选项:&lt;source&gt;&lt;location&gt;${project.basedir}&lt;/location&gt;&lt;includes&gt;&lt;include&gt;**/src/main/config&lt;/include&gt;&lt;/includes&gt;&lt;/source&gt; 如果你可以发布你是如何配置插件的。
    • 嗨,斯蒂芬。通配符似乎不适用于多模块项目的 rpm 插件。
    • 我用适用于我的机器的解决方案更新了我的答案。正如@khmarbaise 提到的,${project.basedir} 属性应该可以解决问题。有两种选择:第一种是使用 basdir 作为位置以及&lt;includes&gt;(那里可以使用通配符)。但是,RPM 将反映文件的整个文件夹结构(例如 /usr/local/module1/src/main/config/...。第二个选项是为每个子模块定义 &lt;source&gt; 配置。然后 RPM 将直接在 &lt;directory&gt; 文件夹中包含文件。
    猜你喜欢
    • 2014-02-03
    • 2011-09-03
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多