覆盖特定于环境的systemPath属性时出现Maven问题

时间:2016-02-19 17:04:44

标签: maven import properties pom.xml system-paths

我遇到了maven构建的问题,如果在Windows上完成(就像过去那样)或Linux(就像我现在想做的那样),其行为方式不同。

我想构建一个依赖于另一个项目的项目,该项目本身导入一个包含Windows路径的pom。

   my project   |           other project
                |
mybuild  -------|------> pom --------> pom with systemPath
            dependency        import
                |

但简而言之,这是我的pom:

<groupId>test.properties</groupId>
<artifactId>buildme</artifactId>
<version>1.0-SNAPSHOT</version>
...
<dependencies>
  <dependency>
    <groupId>test.properties.installme</groupId>
    <artifactId>module</artifactId>
    <version>1.0-SNAPSHOT</version>
    <type>pom</type>
  </dependency>
</dependencies>

我依赖于一个看起来像这样的pom(不在我的控制之下)

<groupId>test.properties.installme</groupId>
<artifactId>module</artifactId>
<version>1.0-SNAPSHOT</version>
...
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>test.properties.installme</groupId>
      <artifactId>dependency</artifactId>
      <version>1.0-SNAPSHOT</version>
      <scope>import</scope>
      <type>pom</type>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
  </dependency>
</dependencies>

问题在于最后一个pom(不在我的控制之下):

<modelVersion>4.0.0</modelVersion>  
<groupId>test.properties.installme</groupId>
<artifactId>dependency</artifactId>
<version>1.0-SNAPSHOT</version>
...
<properties>
  <com.sun.tools.path>D:/java/jdk1.8.0_65/lib/tools.jar</com.sun.tools.path>
</properties>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.sun</groupId>
      <artifactId>tools</artifactId>
      <version>1.8</version>
      <scope>system</scope>
      <systemPath>${com.sun.tools.path}</systemPath>
    </dependency>
  </dependencies>
</dependencyManagement>

我无法控制其他相关项目。我完全同意使用环境变量代替硬编码路径的重构将解决我的问题。 但是,Windows路径是在属性中定义的。 有人会认为根据我的平台覆盖财产的价值就足够了。但事实并非如此。

不幸的是,在这种精确的情况下,maven似乎表现得很差。

在以任何形式应用任何属性覆盖之前(在settings.xml中,-Dproperty =,在root pom中重新定义),maven开始构建有效的pom。在这一步中,如果它找到我上面提到的模式(依赖于另一个pom本身导入包含Windows路径的pom),那么它会说:

The POM for <groupId>:<artifactId>:jar:<version> is invalid, transitive dependencies (if any) will not be available

因此,我的项目需要明确定义第二个项目的所有依赖项。我不能依赖传递依赖,这给我带来了很多麻烦。

为了说明问题,我创建了一个显示问题的最小示例。在这里能找到它: https://github.com/fabricepipart/test-properties

你看到有什么解决方法吗? 有没有办法覆盖属性的值,仍然可以从maven传递依赖中受益?

非常感谢

0 个答案:

没有答案