问题描述
我一直在研究 Jacoco Code - Maven 多模块项目中的声纳集成。我面临一个问题,即 Jacoco 代码覆盖率报告被聚合,但在运行 mvn clean verify 时总是导致 0% 的代码覆盖率。这可能是由于未生成 jacoco.exec 文件。
在使用以下链接中推荐的聚合类型集成 maven jacoco 插件时, https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-maven/maven-multimodule
How to configure multi-module Maven + Sonar + JaCoCo to give merged coverage report?。
我也看到surefire插件设置的argLine是正确的,但是没有生成文件, -javaagent:C:\Users\testuser\.m2\repository\org\jacoco\org.jacoco.agent\0.8.5\org.jacoco.agent-0.8.5-runtime.jar=destfile=C:\Work\ OVT\Workspace-ExportAPI\sbs_export\report\target\jacoco.exec
我的项目结构是,
-> Parent(pom)
-> child1(war)
-> child2(jar)
-> report(jar) -> Jacoco Aggregator jacoco specified as per suggestion provided by above links
以下是使用的 pom.xml 配置。请帮我解决代码覆盖问题和 jacoco.exec 文件问题。
父:pom.xml
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.6.0.1398</version>
</plugin>
</plugins>
</pluginManagement>
</build>
添加相同的配置 Child1,Child2 - pom.xml,
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/../${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
</properties>
报告:pom.xml
<properties>
<sonar.skip>true</sonar.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/../${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
</properties>
<dependencies>
<dependency>
<groupId>com.platform</groupId>
<artifactId>child1</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.platform</groupId>
<artifactId>child2</artifactId>
<version>1.0</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>report</id>
<goals>
<goal>report-aggregate</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)