我正在使用带有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) 我在我的pom.xml文件中配置了Maven JaCoCo插件,如下所示:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jacoco.version>0.5.9.201207300726</jacoco.version>
</properties>
<profiles>
<profile>
<id>jacoco4</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration
<destfile>${project.build.directory}/target/jacoco.exec</destfile>
<datafile>${project.build.directory}/target/jacoco.exec</datafile>
<output>file</output>
<append>true</append>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)
我正在使用Windows 7和apache-maven-3.0.4插件.当我mvn -P jacoco4 install
从cygwin终端或命令提示终端输入时,Maven下载并运行JaCoCo插件,但是该jacoco.exec
文件似乎没有被创建.以下是错误消息:
[ERROR] Unable to read execution data file C:\Users\brownru\workspace64new\vps9\vps-fileserver\target\jacoco.exec: C:\Users\brownru\workspace64new\vps9\vps-fileserver\target\jacoco.exec (The system cannot find the file specified)
java.io.FileNotFoundException: C:\Users\brownru\workspace64new\vps9\vps-fileserver\target\jacoco.exec (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at …
Run Code Online (Sandbox Code Playgroud) 我们有一个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消息.
通过Maven和Surefire插件运行它们时,我的JUnit测试失败(下面的版本信息)。我看到错误消息:
Corrupted STDOUT by directly writing to native stream in forked JVM 4. See FAQ web page and the dump file C:\(...)\target\surefire-reports\2019-03-20T18-57-17_082-jvmRun4.dumpstream
Run Code Online (Sandbox Code Playgroud)
FAQ页面指出了一些可能的原因,但我看不到如何使用此信息来开始解决此问题:
通过直接在派生的JVM中写入本机流而损坏了STDOUT
如果您的测试使用打印到STDOUT的本机库,则会出现此警告消息,因为该库损坏了插件使用的通道,以便将具有测试状态的事件传输回Maven进程。如果通过System.setOut覆盖Java流,则情况甚至更糟,因为该流也应该被破坏,但是Maven将永远看不到测试完成并且构建可能会挂起。
如果使用FileDescriptor.out或JVM打印GC摘要,则会出现此警告消息。
在这种情况下,将显示警告“通过直接写入派生JVM中的本机流而损坏STDOUT”,并且可以在Reports目录中找到转储文件。
如果启用了调试级别,则控制台中将显示流损坏的消息。
它指的是直接将某些本机库打印到STDOUT,但是如果我需要为项目提供库,如何确定哪一个库,即使这样做,也应如何处理?
它提到了“调试级别”,但尚不清楚这是否意味着Maven的调试级别或Surefire插件的调试级别。我启用了Maven的调试功能,但没有看到FAQ中提到的控制台输出。Surefire的调试选项似乎与暂停测试并等待调试器连接到进程有关,而不仅仅是在控制台上显示更多信息。
转储文件似乎也不太有用:
# Created on 2019-03-20T18:42:58.323
Corrupted STDOUT by directly writing to native stream in forked JVM 2. Stream 'FATAL ERROR in native method: processing of -javaagent failed'.
java.lang.IllegalArgumentException: Stream stdin corrupted. Expected comma after third character in command 'FATAL ERROR in native method: processing of -javaagent failed'.
at org.apache.maven.plugin.surefire.booterclient.output.ForkClient$OperationalData.<init>(ForkClient.java:511)
at …
Run Code Online (Sandbox Code Playgroud) 我正进入(状态
由于缺少执行数据文件而跳过JaCoCo执行:/scratch/jenkins/workspace/sonar-test/target/jacoco.exec错误
我的pom档案是:
<profile>
<id>test-coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration combine.self="override">
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<testFailureIgnore>true</testFailureIgnore>
<groups>com.project.test.annotation.QuickTest</groups>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.1.201405082137</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>
</plugins>
</build>
</profile>
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我试图为 Sonarqube 生成 Jacoco 报告。生成文件 jacoco.exec 有效,但在 Eclipse 的 EclEmma 中将它用于 Sonarqube OR 会导致 EOFException(因此两个实现都很糟糕,或者生成的文件是问题所在)。关于这个问题有一些问题但没有解决方案(除了不使用测试覆盖率)。
我创建了一个 Spring Boot 应用程序并尝试使用 Maven 生成 Jacoco 测试覆盖率报告。使用没有问题,mvn test
在目标文件夹中生成了一个jacoco.exec。但是当我尝试将结果上传到 Sonarqube 时,mvn sonar:sonar
我总是收到此错误:
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project project-name: Unable to read XXX\project-name\target\jacoco.exec: EOFException -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
pom.xml
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project project-name: Unable to read XXX\project-name\target\jacoco.exec: EOFException -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
$ mvn sonar:sonar -Dsonar.projectKey=... -Dsonar.host.url=... -Dsonar.login=... -eX
[INFO] Error stacktraces are …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Jacoco 进行代码覆盖,但每次运行时
mvn 干净安装
我在输出日志中收到以下消息:
--- jacoco-maven-plugin:0.7.9:report (post-unit-test) @ myDemo --- 由于缺少执行数据文件而跳过 JaCoCo 执行。
我尝试了这里找到的解决方案:在执行 JaCoCo 时获取“由于缺少执行数据文件而跳过 JaCoCo 执行”?然而添加 {@argLine} 似乎没有帮助。
这是我的 pom.xml 文件,任何见解将不胜感激。谢谢!
<?xml version="1.0" encoding="UTF-8"?>
<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>org.mine</groupId>
<artifactId>myDemo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>myDemo</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>org.mine.mydemo.MainApp</mainClass>
</properties>
<organization>
<!-- Used as the 'Vendor' for JNLP generation -->
<name>Virginia Tech Applied Research</name>
</organization>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.css</include>
<include>**/*.csv</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**.*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources/images</directory> …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Maven 3.8.3、JUnit 5.4.2 和 Jacoco 0.8.2,并且我正在尝试创建测试覆盖率报告。
我有一个仅包含单元测试的项目,但无法运行报告,我反复收到错误:运行时由于缺少执行数据文件而跳过 JaCoCo 执行:
mvn clean jacoco:prepare-agent install jacoco:report
Run Code Online (Sandbox Code Playgroud)
这是我的 pom 的配置方式:
<?xml version="1.0" encoding="UTF-8"?>
<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.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin> …
Run Code Online (Sandbox Code Playgroud) 我有一个maven项目(链接),我想在其上运行代码覆盖.
我mvn test -Pcoverage jacoco:prepare-agent jacoco:report
在主项目pom文件上运行命令,但不生成报告.相反,我得到一个警告说
[INFO] --- jacoco-maven-plugin:0.7.7.201606060606:report (post-test) @ pulsar-discovery-service ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.7.201606060606:prepare-agent (default-cli) @ pulsar-discovery-service ---
[INFO] argLine set to -javaagent:/home/jai1/.m2/repository/org/jacoco/org.jacoco.agent/0.7.7.201606060606/org.jacoco.agent-0.7.7.201606060606-runtime.jar=destfile=/home/jai1/pulsar/pulsar-discovery-service/target/jacoco.exec
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.7.201606060606:report (default-cli) @ pulsar-discovery-service ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
Run Code Online (Sandbox Code Playgroud)
有人可以建议如何使用此pom文件生成代码覆盖率报告.我正在使用apache-maven-3.3.9和testNG.
我正在尝试为我的项目创建一份 jacoco 报告。该项目是java 12版本,jacoco-maven-plugin是0.8.5版本。
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</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 站点
mvn clean install site
Run Code Online (Sandbox Code Playgroud)
我得到:
[INFO] --- jacoco-maven-plugin:0.8.5:prepare-agent (pre-unit-test) @ bowling-game ---
[INFO] argLine set to -javaagent:/home/baptiste/.m2/repository/org/jacoco/org.jacoco.agent/0.8.5/org.jacoco.agent-0.8.5-runtime.jar=destfile=/home/baptiste/IdeaProjects/Bowling-Game/target/jacoco.exec
...
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ bowling-game ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.keywer.kata.bowling.game.frame.state.FrameStateTest
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: …
Run Code Online (Sandbox Code Playgroud)