
Tagträumer
Ich versuche mich einzurichten jacoco
für die Codeabdeckung meines Projekts
Mein Projekt basiert auf Java 1.8
So sehen die Dinge in meinem Projekt aus pom.xml
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.5.10.201208310627</version>
<configuration>
<output>file</output>
<append>true</append>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Dann laufe ich mvn test
und siehe folgendes
$ mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building pennyapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- jacoco-maven-plugin:0.5.10.201208310627:prepare-agent (jacoco-initialize) @ pennyapp ---
[INFO] argLine set to -javaagent:/Users/harit/.m2/repository/org/jacoco/org.jacoco.agent/0.5.10.201208310627/org.jacoco.agent-0.5.10.201208310627-runtime.jar=destfile=/Users/harit/code/idea/pennyapp/target/jacoco.exec,append=true,output=file
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ pennyapp ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ pennyapp ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/harit/code/idea/pennyapp/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ pennyapp ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/harit/code/idea/pennyapp/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ pennyapp ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/harit/code/idea/pennyapp/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.17:test (default-test) @ pennyapp ---
[INFO] Surefire report directory: /Users/harit/code/idea/pennyapp/shippable/testresults
[INFO] Using configured provider org.apache.maven.surefire.junit4.JUnit4Provider
-------------------------------------------------------
T E S T S
-------------------------------------------------------
objc[13225]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Running HelloTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.1 sec - in HelloTest
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.523 s
[INFO] Finished at: 2014-08-19T17:56:33-07:00
[INFO] Final Memory: 10M/119M
[INFO] ------------------------------------------------------------------------
und dann laufe ich mvn jacoco:report
und ich sehe
$ mvn jacoco:report
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building pennyapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- jacoco-maven-plugin:0.5.10.201208310627:report (default-cli) @ pennyapp ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.176 s
[INFO] Finished at: 2014-08-19T17:56:51-07:00
[INFO] Final Memory: 11M/112M
[INFO] ------------------------------------------------------------------------
Dann schaue ich zu target/site/jacoco/index.html
und siehe folgendes
Frage
– Was ist in der Konfiguration falsch?
– Wie kann ich einen Bericht erstellen?
Vielen Dank

Kolargol00
Gibt es einen bestimmten Grund, warum Sie eine veraltete Version des JaCoCo-Plugins verwenden? Für die Unterstützung von Java 8 müssen Sie mindestens Version 0.7.0 verwenden (siehe Änderungsprotokoll).
In Ihrer Konfiguration ist das Berichtsziel an die Überprüfungsphase gebunden, läuft also mvn test
generiert keinen Bericht, da die Überprüfungsphase nicht ausgeführt wird (vor dem verifizieren kommt die testphase). Sie müssen verwenden mvn verify
um Tests auszuführen und den Bericht zu erstellen.
Das JaCoCo-Projekt bietet Beispielkonfigurationen für Maven. Du kannst es versuchen “Diese POM-Datei für ein JAR-Projekt führt JUnit-Tests unter Codeabdeckung aus und erstellt einen Abdeckungsbericht“.

Pierrick HYMBERT
JaCoco Maven Plugin überschreibt Surefire argLine, falls Sie auch argLine überschreiben müssen, achten Sie darauf, die Variable argLine beizubehalten:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xmx1024M ${argLine}</argLine>
</configuration>
</plugin>
Beachten Sie, dass Sie diesen Eigenschaftsnamen ändern können, wie in beschrieben jacoco-Plugin-Dokumentation.
Das hat bei mir funktioniert:
mvn clean install
mvn site
Obwohl die Mindestcodeabdeckung nicht erreicht wurde und mvn clean install
gescheitert, die mvn site
Der Build war erfolgreich und der Abdeckungsbericht wurde erstellt unter:
.../target/site/jacoco/index.html

Benutzer2739602
Folgen funktioniert bei mir ohne Probleme
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
HINWEIS: Die Phase ist „Test“, um den Bericht zu erstellen, sobald die Tests ausgeführt wurden
Ich hatte das gleiche Problem. Das Problem war, dass ich das jacoco-Plugin in die hinzugefügt hatte <plugins>
das stand drin <pluginManagment>
Schild.
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
...
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
...
</plugins>
</pluginManagement>
Nach hinzufügen <plugins>
als direktes Kind von <build>
alles funktioniert gut.
<build>
....
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
...
<build>

Parameshwar
Hatte ein ähnliches Problem, ich kenne die Ursache nicht, aber das Vermeiden im Build löste das Problem
<pluginManagement>
Nach dem Pom, der für mich geklappt hat
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>SampleSpring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>SampleSpring</name>
<description>Demo project for SampleSpring</description>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<start-class>com.example.spring.SampleSpringApplication</start-class>
<jacoco.version>0.8.3</jacoco.version>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Testing -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<!--jacoco plugin -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<configuration>
<output>file</output>
<append>true</append>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<!--jacoco plugin end -->
<!--Sonarqube plugin -->
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.6.0.1398</version>
</plugin>
<!--Sonarqube plugin end -->
</plugins>
</build>
</project>

Murat Yıldız
Bevor Sie die anderen Problemumgehungen ausprobieren, überprüfen Sie zuerst „Modus ‚Test überspringen‘ umschalten“ ist in der Maven-Symbolleiste in IntelliJ IDEA nicht aktiv.

10145400cookie-checkmaven jacoco: Bericht zur Codeabdeckung wird nicht generiertyes
Gibt es einen bestimmten Grund, warum Sie eine veraltete Version des JaCoCo-Plugins verwenden? Für die Unterstützung von Java 8 müssen Sie mindestens Version 0.7.0 verwenden (siehe Änderungsprotokoll).
– Kolargol00
20. August 2014 um 3:14 Uhr
läuft alte Version von
jacoco
war problem. Danach ist es behoben– Tagträumer
20. August 2014 um 4:17 Uhr