如何使用 `-Xbootclasspath/p:my.jar` 选项 运行 `jacoco-maven-plugin`?
How to run `jacoco-maven-plugin` with `-Xbootclasspath/p:my.jar` option?
为了成功 运行 我的单元测试,我必须为 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>
如 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>
为了成功 运行 我的单元测试,我必须为 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>
如 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>