我有一个maven多模块项目,我正在使用jacoco-maven进行代码覆盖率报告.不应该报告某些类,因为它们是Spring配置,我对它们不感兴趣.
我已经宣布了maven-jacoco插件如下:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<configuration>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
<exclude>some.package.*</exclude>
<exclude>**/*Config.*</exclude>
<exclude>**/*Dev.*</exclude>
<exclude>some/package/SomeClass.java</exclude>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
问题是,当我执行mvn clean verifyjacoco时,仍会报告应该已被排除的类,因为我的xml配置指出了.如何正确配置?
我正在使用JaCoCo,它正在考虑Lombok生成的方法(在字节码中生成,而不是源代码中的跟踪).如何配置JaCoCo忽略它们?
我最近搬到了另一台计算机,需要重置我的所有环境。
所以,这个测试之前是有效的。
但我不记得我之前使用的是哪个版本的Java/JDK。
嗯,问题是:
java.lang.instrument.IllegalClassFormatException: Error while instrumenting path/to/class
Run Code Online (Sandbox Code Playgroud)
我正在使用Jacoco“0.8.1”
java --version
openjdk 17.0.1 2021-10-19
Run Code Online (Sandbox Code Playgroud)
和 JDK 1.8
谁能知道如何处理它?
我们有一个Maven多模块项目,由父(HelloWorld)和不同的子(HelloWorldServices和HelloWorldPresentation)组成,并使用Jenkins构建.
运行成功测试后的错误是
[INFO] --- jacoco-maven-plugin:0.7.6.201602180812:report (default-cli) @ HelloWorldServices ---
[INFO] Skipping JaCoCo execution due to missing execution data file:/var/lib/jenkins/workspace/HelloWorld/HelloWorldServices/target/jacoco.exec
Run Code Online (Sandbox Code Playgroud)
它之前的线条说
[INFO] --- jacoco-maven-plugin:0.7.6.201602180812:prepare-agent (default-cli) @ HelloWorldServices ---
[INFO] argLine set to -javaagent:/var/lib/jenkins/.m2/repository/org/jacoco/org.jacoco.agent/0.7.6.201602180812/org.jacoco.agent-0.7.6.201602180812-runtime.jar=destfile=/var/lib/jenkins/workspace/HelloWorld/HelloWorldServices/target/jacoco.exec
Run Code Online (Sandbox Code Playgroud)
这是我定义父pom JaCoCo插件的方式:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<configuration>
<destfile>${project.artifactId}/target/jacoco.exec</destfile>
<datafile>${project.artifactId}/target/jacoco.exec</datafile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
在没有pom的情况下,我明确提到了万无一失.我也尝试了你在任何地方找到的argLine配置,但都具有相同的结果.无论我做什么,JaCoCo .exec文件从未创建过.至于目标,我用
mvn clean install jacoco:prepare-agent jacoco:report
Run Code Online (Sandbox Code Playgroud)
因为当我省略jacoco目标时,它甚至不显示INFO消息.
我使用 jacoco 进行覆盖率报告。当我查看 jacoco 报告时,报道似乎很好。但是在 Sonarqube 中,覆盖率很低,因为它说@Data来自lombok 的注释不被测试覆盖。
已编译的类被标记为@Generated但它不会被声纳忽略。
如何排除@Data分析?
我们有一个多模块多语言maven java项目,使用jacoco进行覆盖分析.模块的主要部分是带有REST API的后端(Java代码),我们的webapp模块包含前端(AngularJS)和java中的Integration-Tests.我们的Jacoco-IT.exec文件包含大约100Kb的数据,因此我们猜测可以收集集成测试的一些Coverage数据.然而,我们无法在SonarQube中看到任何报道(使用版本5.0和4.5)
我们运行构建项目并运行集成测试
mvn clean install
Run Code Online (Sandbox Code Playgroud)
用数据分析数据
mvn sonar:sonar
Run Code Online (Sandbox Code Playgroud)
项目配置为多语言,但我们只是分析了java代码(我们曾经有过单语言配置,但与覆盖数据相关的结果没有差异)
我们的父母POM:
<properties>
<hibernate.version>4.2.2.Final</hibernate.version>
<spring.version>3.2.3.RELEASE</spring.version>
<resteasy.version>3.0.4.Final</resteasy.version>
<cucumber.version>1.1.3</cucumber.version>
<selenium-java.version>2.33.0</selenium-java.version>
<!-- Sonar -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.itReportPath>${project.basedir}/../target/jacoco-it.exec</sonar.jacoco.itReportPath>
<jacoco.dataFile>${project.basedir}/../target/jacoco-it.exec</jacoco.dataFile>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<debug>true</debug>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
</plugin>
</plugins>
<pluginManagement>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
</plugin>
</pluginMangement> …Run Code Online (Sandbox Code Playgroud) configuration integration-testing maven sonarqube jacoco-maven-plugin
我试图通过Maven做一个简单的JaCoCo报告,我一直得到同样的错误.这是我的插件的片段.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<executions>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.01</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
当我跑步时,mvn clean install jacoco:check我得到以下内容
无法执行目标org.jacoco:jacoco-maven-plugin:0.7.2.201409121644:check(default-cli)on project ###########:目标org.jacoco的参数'rules':jacoco -maven-plugin:0.7.2.201409121644:检查丢失或无效 - > [帮助1]
我已经尝试将版本从0.6.3更改为0.7.2以及介于两者之间的每个版本.据我所知,这看起来像0.6.3以上的任何版本的有效配置,甚至最初取自他们在下面的链接中找到的示例(我刚刚删除除检查目标之外的所有内容):
http://www.eclemma.org/jacoco/trunk/doc/maven.html
如果我运行-X选项,我得到以下堆栈跟踪:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jacoco:jacoco-maven-plugin:0.7.2.201409121644:check (default-cli) on project science-open: The parameters 'rules' for goal org.jacoco:jacoco-maven-plugin:0.7.2.201409121644:check are missing or invalid
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:220)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116) …Run Code Online (Sandbox Code Playgroud) 似乎有几个问题,这些问题已经过时了,并且从Jacoco的Java 8支持改变了一些问题.
我的项目包含以下结构
pom.xml
|
|
-----sub module A pom.xml
|
|
-----sub module B pom.xml
|
|
-----sub module C pom.xml
Run Code Online (Sandbox Code Playgroud)
我已经配置了main pom这样的
主POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>jacoco-multi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>projectA</module>
<module>projectB</module>
</modules>
<properties>
<jacoco.version>0.5.7.201204190339</jacoco.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.10</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3.RC2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3.RC2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<destFile>${project.basedir}/../target/jacoco.exec</destFile>
<append>true</append>
</configuration> …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试将 JaCoCo 添加为我的 Spring Boot maven 项目的依赖项,以查看我的单元测试的代码覆盖率。但是,当我运行测试时,它失败并显示错误。
Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.3:report (report) on project test-rest-service: An error has occurred in JaCoCo report generation. Error while creating report: malformed input around byte 2 -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
所有测试都通过而没有失败,所以这不是问题。
JaCoCo 的依赖项是:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
生成了 JaCoCo.exec 文件,但我无法打开它来生成报告。我究竟做错了什么?
在我们的项目中,我们使用jacoco-maven-plugin并在构建过程中出现此错误:
[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.5:check (jacoco-check) on project my-project: Coverage checks have not been met. See log for details.
Run Code Online (Sandbox Code Playgroud)
我知道最好修复覆盖范围等等。但有时我只需要快速构建一个项目。是否有某种参数用于此目的?喜欢mvn clean install -Dskip.jacoco.check=true或其他方式快速跳过此检查?