我在我的pom.xml中配置了一些Maven插件。如果測試正在運行,我只想執行這些插件(可以使用-Dmaven.test.skip=true
或-DskipTests
跳過測試)。有條件地執行maven插件
其中一個插件綁定到process-classes
構建生命週期階段,另一個綁定到pre-integration-test
階段。
我在我的pom.xml中配置了一些Maven插件。如果測試正在運行,我只想執行這些插件(可以使用-Dmaven.test.skip=true
或-DskipTests
跳過測試)。有條件地執行maven插件
其中一個插件綁定到process-classes
構建生命週期階段,另一個綁定到pre-integration-test
階段。
您可以使用配置文件與特殊的激活條件是這樣的:
<project>
...
<profiles>
<profile>
<id>my-test-plugins</id>
<activation>
<property><name>!maven.test.skip</name></property>
<property><name>!skipTests</name></property>
</activation>
<build>
<plugins>
<!-- define your plugins here -->
</plugins>
</build>
</profile>
</profiles>
</project>
更多信息,你可以在這裏找到:只有當我設置也值
http://books.sonatype.com/mvnref-book/reference/profiles-sect-activation.html
感謝您的鏈接到Maven書。除了在此提出/回答的內容之外,真正有助於學習。 – 2012-07-28 11:23:26
如何使用IF條件而不使用配置文件,因爲它們不適合我? 基本上,我有整套項目的配置文件。對於一個子模塊,我需要根據當前配置文件爲aspect-j插件選擇配置。我怎麼能用建議的模型做到這一點,不知道... – Zorkus 2013-06-26 10:49:57
這實際上工作嗎?看起來你只能在
最後一個例子中的工作:
<property>
<name>wsdl2java</name>
<value>true</value>
</property>
這是**不是**原始問題的答案。要批評或要求作者澄清,在他們的帖子下留下評論 - 你總是可以評論你自己的帖子,一旦你有足夠的[聲譽](http://stackoverflow.com/help/whats-reputation),你會能夠[評論任何帖子](http://stackoverflow.com/help/privileges/comment)。 – DavidPostill 2015-02-03 15:52:35
我有一個類似的情況,我想有一個插件_(tomcat7-maven -plugin)_可用於本地開發,但未在CI構建中引用_(TeamCity,僅使用來自Artifactory回購的經批准的工件)_。按照@tenshi的建議,我在'id = localhost-server'中添加了一個'profile'元素,但排除了'activation'元素。然後,我在我的'settings.xml'中添加了一個'activeProfile'元素,這樣它就只能在我的本地環境中處於活動狀態。 – 2013-04-08 14:13:48
請參閱我的帖子,詳細的例子。 http://stackoverflow.com/questions/7513319/maven-command-line-arguments/33807842#33807842 – Abhishek2k6 2015-11-19 15:29:13