我正在使用带有jacoco插件的maven 来生成代码覆盖率指标.我有在配置一些困难神火由所需的Java插件的选项jacoco插件.我已经在Stack Overflow上看到了一些关于此问题的答案,但有些东西对我不起作用.
我有一个多模块项目,我的一个模块配置了surefire插件,如下所示:
foo/pom.xml:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-XX:MaxPermSize=512m</argLine>
</configuration>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
这按预期工作.
现在我想结合jacoco获取代码覆盖率的指标,所以我加了一个代码覆盖率配置文件,处理所有jacoco配置:
parent/pom.xml:
<profile>
<id>CodeCoverage</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals><goal>prepare-agent</goal></goals>
<configuration>
<propertyName>surefire.argLine</propertyName>
</configuration>
...
</execution>
<executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
Run Code Online (Sandbox Code Playgroud)
它是在这里看到的是,如果代码覆盖率指定配置文件,然后jacoco插件配置为使用surefire.argLine属性,该属性用于配置argLine为万无一失插件.
然后我更新了foo模块的pom.xml文件,以使用jacoco插件生成的属性:surefire.argLine
foo/pom.xml:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${surefire.argLine} -XX:MaxPermSize=512m</argLine> …Run Code Online (Sandbox Code Playgroud) 我在用:
SONAR v.3.2(它有jacoco)
Maven 3.0.4
遵循“ http://johndobie.blogspot.in/2012/05/easy-unit-and-integration-code-coverage.html#comment-form ”以获得单元和IT测试的单独代码覆盖率。但 IT 测试覆盖率显示为 0%。它生成单独的 jacoco-unit.exec (44kb) 和 jacoco-it.exec (14kb),但覆盖率仅显示在 SONAR 上的单元测试中。
日志显示为:
[INFO] [13:10:23.515] Sensor SquidSensor done: 9437 ms
[INFO] [13:10:23.515] Sensor JaCoCoSensor...
[INFO] [13:10:23.578] Analysing ...\target\coverage-reports\jacoco-unit.exec
[INFO] [13:10:30.390] Sensor JaCoCoSensor done: 6875 ms
[INFO] [13:10:30.390] Sensor JaCoCoItSensor...
[INFO] [13:10:30.390] Analysing ...\target\coverage-reports\jacoco-it.exec
[INFO] [13:10:30.469] Sensor JaCoCoItSensor done: 79 ms
[INFO] [13:10:30.484] Sensor SurefireSensor...
[INFO] [13:10:30.484] parsing ...\target\surefire-reports
[INFO] [13:10:30.828] Sensor SurefireSensor done: 344 ms
[INFO] [13:10:30.828] Sensor CpdSensor...
[INFO] [13:10:30.828] SonarEngine is used …Run Code Online (Sandbox Code Playgroud)