2016-12-01 21 views
0

要成功運行我的單元測試,我必須爲JVM提供一些替換的標準類。因此,我用下面的配置maven-surefire-plugin如何用`-Xbootclasspath/p:my.jar`選項運行`jacoco-maven-plugin`?

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.19.1</version> 
    <configuration> 
    <skipTests>${skipUTs}</skipTests> 
    <argLine>-Xbootclasspath/p:my.jar</argLine> 
    </configuration> 
</plugin> 

plugin/configuration/argLine添加,沒有什麼特別的。但我怎麼能告訴jacoco同樣的事情?該jacoco沒有configuration/argLine :(

我已經在我的pom.xml文件配置如下Maven的JaCoCo插件:

<plugin> 
    <groupId>org.jacoco</groupId> 
    <artifactId>jacoco-maven-plugin</artifactId> 
    <version>0.7.5.201505241946</version> 
    <configuration> 
    <skip>${skipUTs}</skip> 
    <!-- NO ONE (((((
    <argLine>-Xbootclasspath/p:my.jar</argLine> 
    --> 
    </configuration> 
    <executions> 
    <execution> 
     <id>default-prepare-agent</id> 
     <goals> 
     <goal>prepare-agent</goal> 
     </goals> 
    </execution> 
    <execution> 
     <id>default-report</id> 
     <phase>prepare-package</phase> 
     <goals> 
     <goal>report</goal> 
     </goals> 
    </execution> 
    <execution> 
     <id>default-check</id> 
     <goals> 
     <goal>check</goal> 
     </goals> 
     <configuration> 
     <rules> 
      <rule implementation="org.jacoco.maven.RuleConfiguration"> 
      <element>BUNDLE</element> 
      <limits> 
       <limit implementation="org.jacoco.report.check.Limit"> 
       <counter>COMPLEXITY</counter> 
       <value>COVEREDRATIO</value> 
       <minimum>1.0</minimum> 
       </limit> 
      </limits> 
      </rule> 
     </rules> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 
+0

可能的重複[無法在maven中使用jacoco JVM參數和surefire JVM參數](http://stackoverflow.com/questions/23190107/cannot-use-jacoco-jvm-args-and-surefire-jvm-args -together合行家) – Godin

回答

1

documentation of prepare-agent說 - 它只是設置用於財產argLine通過maven-surefire-plugin,你有兩個選擇添加額外的參數:

<properties> 
    <argLine>-your -extra -arguments</argLine> 
</properties> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <configuration> 
    <!-- no argLine here --> 
    </configuration> 
</plugin> 

或使用late property evaluation feature of maven-surefire-plugin

<properties> 
    <!-- empty to avoid JVM startup error "Could not find or load main class @{argLine}" in case when jacoco-maven-plugin not executed --> 
    <argLine></argLine> 
</properties> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <configuration> 
    <argLine>@{argLine} -your -extra -arguments</argLine> 
    </configuration> 
</plugin> 
相關問題