如何使用`-Xbootclasspath / p:my.jar`选项运行`jacoco-maven-plugin`?

时间:2016-12-01 14:46:35

标签: maven-3 maven-plugin jacoco jacoco-maven-plugin

要成功运行我的单元测试,我必须为JVM提供一些替换的标准类。因此,我对maven-surefire-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>

1 个答案:

答案 0 :(得分: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>