2

在我的Maven構建中,我有一小塊Ant代碼需要在Surefire開始執行一些配置之前運行。如何在testCompile和測試階段之間執行Maven的antrun(在Surefire執行之前)?

該代碼與antrun執行,但我不能得到antrun在Surefire之前執行。

這是我構建的輸出中的相關章節:

[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ com...tests --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compiling 7 source files to C:\...\com...tests\target\test-classes 
[INFO] 
[INFO] --- maven-surefire-plugin:2.16:test (default-test) @ com...tests --- 
[INFO] Surefire report directory: C:\...\com...tests\target\surefire-reports 

基本上我需要antrun maven-compiler-plugin:3.1:testCompilemaven-surefire-plugin:2.16:test之間執行。

我嘗試將antrun綁定到測試階段,並將它放在POM文件中的surefire插件之前,但它始終在Surefire插件之後執行。我也嘗試將它配置爲在testCompile階段運行,並將其放在maven-compiler-plugin插件之後,但是沒有成功。它在surefire之後執行。

有誰知道如何讓它在這兩者之間執行?

謝謝!

愛德華

+0

通過Ant無法通過Maven完成什麼?你能給我們更多的細節嗎? – khmarbaise

+0

在這種情況下,我正在更新屬性文件。它可能在Maven中完成,但更新它的命令來自包含'sed'命令的文件,因此antrun似乎是讀取該文件並在測試運行之前執行sed命令的最簡單方法。 –

+0

爲什麼你要更新屬性文件,因爲你在src/test/resources'中有第二個集合用於測試,而不會干擾'src/main/resources'中的生產屬性文件。 – khmarbaise

回答

4

您可以執行process-test-classes生命週期階段的antrun插件,如果你看一看到這僅僅是test-compiletest

+0

正是我需要的,謝謝! –

4

之間的build life-cycle你可以看到有編譯之間的幾個步驟/ testCompile和測試...

compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy 

所以我建議你的情況,而這正是你所需要的點使用process-test-classes

+0

不能相信我錯過了!我正在尋找另一個Maven幫助頁面,那個階段沒有列出!非常感謝! (必須標記另一個答案是正確的,因爲它是第一個,但upvoted你的) –

相關問題