我正在开发一个多模块 Maven 项目,结构如下:
Parent
|----Client
|----Server
|----End2End
Server 是一个生成 REST 接口(interface)的 Spring Boot 应用程序。 Client 是一个使用 REST 接口(interface)的简单 swing 应用程序,End2End 是一个包含一些端到端测试(客户端/服务器)的模块。进入真正的问题,这是我在父 pom 中的属性:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<jacoco.data.file>${project.build.directory}/jacoco.exec</jacoco.data.file>
<jacoco.report.path>${project.reporting.outputDirectory}</jacoco.report.path>
<sonar.language>java</sonar.language>
<sonar.jacoco.reportPaths>${project.reporting.outputDirectory}</sonar.jacoco.reportPaths>
</properties>
这是我的构建部分
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
<configuration>
<jacocoReports>
<jacocoReport>${project.reporting.outputDirectory}/jacoco.xml</jacocoReport>
</jacocoReports>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<configuration>
<excludes>
<exclude>**/ServerApplication.*</exclude>
<exclude>**/DatabaseGrid.*</exclude>
<exclude>**/WebSecurityConfig.*</exclude>
<exclude>**/App.*</exclude>
<exclude>**/DatabaseGrid.*</exclude>
<exclude>**/GridFromServer.*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<!-- binds by default to the phase "initialize" -->
<goal>prepare-agent</goal>
<!-- binds by default to the phase "verify" -->
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
当我启动诸如这样的构建时
mvn clean verify coveralls:report
工作服上正确报告了我的总体代码覆盖率。 但是当我启动时:
mvn clean verify sonar:sonar
分析有效,但代码覆盖率始终为 0%。我确信我弄错了报告路径,jacoco 报告位于parent/target/jacoco.exec 中。谁能帮我吗?
最佳答案
<sonar.jacoco.reportPaths>${project.reporting.outputDirectory}</sonar.jacoco.reportPaths>
指定目录,而根据SonarQube documentation应指定 exec 文件。
关于java - 多模块项目中 Sonar 覆盖范围始终为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49799483/