[英]SonarQube not measuring code coverage with Java 8
Here in my workplace we were requested to update, among other things in our projects, the java version specified in the properties (from 7 to 8). 在这里,我们在工作场所中要求我们更新项目中指定的Java版本(从7到8)。
But, after I change the content in the <java.version>
tag from 1.7 to 1.8 and do a Maven build of the project with 但是,在将
<java.version>
标记中的内容从1.7更改为1.8并使用以下命令对项目进行Maven构建后
clean package install cobertura:cobertura -Dcobertura.report.format=xml org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar -Dsonar.projectKey=myproject -Dsonar.projectName=myproject
The code coverage goes to 0% (at the page returned after it completes the analysis). 代码覆盖率达到0%(在完成分析后返回的页面上)。 All the other measures, like code smells and duplications continue working just fine.
所有其他措施,例如代码气味和重复项,都可以正常运行。
What are possible reasons for this/possible solutions? 这个/可能的解决方案的可能原因是什么? I tried looking everywhere and no one here knows why this might be happening.
我尝试到处寻找,这里没有人知道为什么会发生这种情况。 Here is some information in the pom.xml of the parent project:
这是父项目的pom.xml中的一些信息:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<artifact-version>2.0.0-SNAPSHOT</artifact-version>
</properties>
<dependencies>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>1.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
</configuration>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.6.0.1398</version>
</plugin>
</plugins>
</build>
I'm not completely familiarized with the inner workings of the projects, or with how Maven works, so I don't know if I'm missing relevant information. 我对项目的内部运作或Maven的工作方式并不完全熟悉,所以我不知道我是否缺少相关信息。 I will add more info if necessary.
如有必要,我将添加更多信息。
While we didn't understand exactly the reason for the drop of coverage to 0%, we found out that adding the Jacoco plugin fixes this problem. 虽然我们不完全了解将覆盖率降低到0%的原因,但我们发现添加Jacoco插件可以解决此问题。 Just add to the pom:
只需添加到pom:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.0</version>
<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>
</executions>
</plugin>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.