要擴展@ rich-seller的答案和@ Bostone的自我回答,似乎不可能有父母POM定義的設置一些配置文件作爲替代方案,並且子POM默認選擇這些配置文件中的一個,同時允許您臨時替代子選項(即在CLI上)。考慮該使用一些框架和相關的插件,包括其兩個版本,我們可以假設通過屬性定義項目父POM:
<profiles>
<profile>
<id>newest</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<framework.version>2.0</framework.version>
<plugin.version>2.0</plugin.version>
</properties>
</profile>
<profile>
<id>older</id>
<activation>
<property>
<name>older.framework</name>
<value>true</value>
</property>
</activation>
<properties>
<framework.version>1.1</framework.version>
<plugin.version>1.1</plugin.version>
</properties>
</profile>
</profiles>
現在的孩子從默認這個父POM繼承會使用2.0,你會期望,-Polder
或-Dolder.framework=true
將嘗試使用舊框架構建它(例如,測試兼容性)。然而,你不能在孩子POM
<properties>
<older.framework>true</older.framework>
</properties>
寫,有older
配置文件被自動激活。如果newest
默認情況下不是活動的,那麼您可以使用基於文件的激活來使該模塊與1.1版本構建,但是,對於2.0來說暫時運行它並不容易:據我所知,older
和newest
配置文件在您通過-Pnewest
,所以你需要明確禁用其他配置文件,如果你有十幾個是不合理的。所以除了簡介信息複製到子POM只是無解:
<properties>
<framework.version>1.1</framework.version>
<plugin.version>1.1</plugin.version>
</properties>
此時-Pnewest
將不工作覆蓋這些屬性,所以你需要使用-Dframework.version=2.0 -Dplugin.version=2.0
。
換句話說,配置文件僅在所有子模塊默認使用相同配置文件(此處爲newest
)時纔有用。如果它們中的一些通常用1.1構建而另一些用2.0構建,則配置文件是無用的。
看起來像這樣是Maven核心增強或者Maven 3構建擴展的用例。想到http://docs.codehaus.org/display/MAVEN/Custom+Profile+Activators和https://github.com/maoo/maven-tiles。
是的。我接受這個,因爲它建立在我的答案上,我通常不喜歡接受我自己的 – Bostone 2012-08-31 17:04:18
非常有用的信息。並感謝關於基於文件的激活的提示;這非常乾淨地解決了我的問題。 – Allan 2012-11-30 17:27:08