在没有公共父级的子模块中重用 maven 属性



在maven多模块项目中,有一个子模块需要从外部父项目继承。因此,它不能像其他子模块一样从父模块继承,并且这些子模块不能继承该外部父模块(因此不能选择使外部项目成为整个层次结构的父项目(。

有没有办法消除此类模块与层次结构其余部分之间的属性重复?

parent绒球.xml

<properties>
<foo>bar</foo>
</properties>
<modules>
<module>child</module>
<module>stepchild</module>
</modules>

child绒球.xml

<parent>
<groupId>my</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<description>foo can be used: ${foo}</description>

stepchild绒球.xml

<parent>
<groupId>external</groupId>
<artifactId>parent</artifactId>
<version>35</version>
<relativePath/>
</parent>
<description>foo does not get substituted: ${foo}</description>

除了其他用户在上面的评论中发现的所有问题之外,您还可以使用可重用的文件"my.properties"设置属性,其中包含 foo=bar

并添加到 Maven:

<build>    
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/../project-parent/my.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

最新更新