我想创建一个结构如下的maven项目:
A
|--pom.xml
|--B
|--pom.xml
|--C
|--pom.xml
其中A、B、C是文件夹,B的pom.xml和C的pom.xml是A的pom.xml的子项。我想在 B 的 pom.xml 中包含以下部分:
<properties>
<some.property>B</some.property>
</properties>
在 C 中:
<properties>
<some.property>C</some.property>
</properties>
我想在 A something 中根据某些属性的值定义其他几个属性的值。因此,例如,在伪代码中,A 会做这样的事情:
if ( some.property == 'B') then
some.other.property = 'some-value-based-on-b'
else if ( some.property == 'C') then
some.other.property = 'some-value-based-on-c'
...
我想运行 mvn clean install 引用 A 的 pom.xml(其中包含一个指向 B 和 C 的模块部分),因此,据我所知,我不能为此使用配置文件(因为在运行的 maven2 项目中在同一个 react 器中继承相同的 Activity 配置文件。我可以使用 maven3,但找不到它是否改变了任何东西)。
有人知道怎么做吗?
谢谢,
最佳答案
开箱即用,maven 无法执行此操作,并且不鼓励使用变通方法(属性不应在生命周期内更改)。
虽然有几种解决方法,但我最喜欢的是 gmaven plugin ,这让你 embed Groovy code in the pom .
以下代码片段会将属性“abc”设置为“bar”或“baz”,具体取决于属性“def”是否包含“foo”:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source><![CDATA[
pom.properties['abc']=
pom.properties['def'].contains('foo') ? 'bar' : 'baz';
]]></source>
</configuration>
</execution>
</executions>
</plugin>
顺便说一句,文档已经过时,插件版本现在是 1.3 并且 groupId 已更改。这是 the current version .
关于java - 根据其他属性值在 Maven 中定义属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4218017/