0

我遇到了一个 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=,在根 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 传递依赖项?

非常感谢

4

0 回答 0