2014-03-03 36 views
0

我在系統屬性中使用$ {surefire.forkNumber}在我的pom中。根據maven documentation,它應該被解析爲當前正在運行的fork的數量。但它解決爲空。
下面是我的POM文件的片段:

<plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-failsafe-plugin</artifactId> 
       <version>2.16</version> 
       <configuration> 
        <forkCount>3</forkCount> 
        <reuseForks>true</reuseForks> 
        <redirectTestOutputToFile>true</redirectTestOutputToFile> 
        <systemPropertyVariables> 
         <database.name>My_Test_Schema_${surefire.forkNumber}</database.name> 
        </systemPropertyVariables> 
       </configuration> 
</plugin> 

我錯過了什麼?

請,有人扔一些輕...

+0

請發送完整的pom(或至少插件定義)。 – blackbuild

回答

-1

您可以使用佔位符$ {} surefire.forkNumber內argLine,或在系統屬性

You should pass the value to place holder either these three ways.. 

1. command line argument like mvn test -Dsurefire.forkNumber=8 

2. set by systemPropertyVariables System.setProperty("surefire.forkNumber",8); 

3. set by pom properties tag like 

<properties> 
     <surefire.forkNumber>8</surefire.forkNumber> 
    </properties> 
+1

第一個選項將被解析爲一個字符串,即無論使用何種屬性,它都將被替換爲8. surefire.forkNumber是屬性中構建的maven。它的實際功能是將1替換爲使用它的n個字符串,其中n是插件配置中提及的分支數。爲了更好的理解,你可以閱讀它[這裏](http://maven.40175.n5.nabble.com/SureFire-2-16-doesn-t-respect-forkCount-td5771850.html)。猜測另外兩個選項同樣也會結束。 – EmeraldTablet

1

通行證通過VM -D設置在argLine中:

<argLine>-Ddatabase.name=My_Test_Schema_${surefire.forkNumber}</argLine> 

我發現systemPropertyVariables非常脆弱。請參閱SureFire 2.16 doesn't respect forkCount(這對我來說無論如何都不適用於使用surefire 2.17的單向或雙向工作)。