【问题标题】:How to run `jacoco-maven-plugin` with `-Xbootclasspath/p:my.jar` option?如何使用 `-Xbootclasspath/p:my.jar` 选项运行 `jacoco-maven-plugin`?
【发布时间】:2017-04-16 06:17:42
【问题描述】:

为了成功运行我的单元测试,我必须为 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>

【问题讨论】:

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


【解决方案1】:

documentation of prepare-agent 中所述 - 它只是设置maven-surefire-plugin 使用的属性argLine,并且您有两个选项可以添加其他参数:

<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>

【讨论】:

    猜你喜欢
    • 2016-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-11
    • 2021-06-20
    • 1970-01-01
    • 2019-12-11
    相关资源
    最近更新 更多