Maven JaCoCo plugin not compatible with Surefire plugin with fork options

10,675 views
Skip to first unread message

justin...@yahoo.com

unread,
Jul 17, 2013, 9:47:09 AM7/17/13
to jac...@googlegroups.com
Hi,

Below is a simple pom.xml that demonstrates that the Maven JaCoCo plugin is not compatible with the Surefire plugin when the surefire forkMode (or forkCount / reuseFork) flags are used.

This is a problem for us because our unit tests are running out of PermGen and changing the fork mode can solve this problem for us, but then Sonar doesn't work because of this incompatibility.

We always get the error message:

[ERROR] Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.15:test failed: java.lang.Error: Unable to access JaCoCo Agent - make sure that you use JaCoCo and version not lower than 0.6.2.; nested exception is java.lang.Error: Unable to access JaCoCo Agent - make sure that you use JaCoCo and version not lower than 0.6.2. org/jacoco/agent/rt/RT: org.jacoco.agent.rt.RT -> [Help 1]

<?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.xxxxx</groupId>
<artifactId>xxxxx</artifactId>
<version>1.0.0</version>

<properties>
<buildType>Placeholder</buildType>
<isRelease>true</isRelease>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.language>java</sonar.language>
<!-- Tells Sonar to run the unit tests -->
<sonar.dynamicAnalysis>true</sonar.dynamicAnalysis>
<!-- Tells Sonar to use JaCoCo as the code coverage tool -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
</properties>

<build>
<plugins>

<!-- junit plugin config -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<forkMode>always</forkMode>
<!--<argLine>-XX:MaxPermSize=1024m ${argLine}</argLine>-->
<properties>
<property>
<name>listener</name>
<value>org.sonar.java.jacoco.JUnitListener</value>
</property>
</properties>
</configuration>
</plugin>

<!-- for Sonar -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.3.201306030806</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.codehaus.sonar-plugins.java</groupId>
<artifactId>sonar-jacoco-listeners</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Marc Hoffmann

unread,
Jul 17, 2013, 1:18:44 PM7/17/13
to jac...@googlegroups.com
Hi,

this looks like a SonarQube issue: "Unable to access JaCoCo Agent -
make sure that you use JaCoCo and version not lower than 0.6.2" is not a
JaCoCo error message.

Can you please report this issue at SonarQube?

Thanks,
-marc

gurv...@gmail.com

unread,
Jun 20, 2014, 10:51:50 AM6/20/14
to jac...@googlegroups.com
Hi,

I have the issue, but I don't get what would be the link with sonarqube ? This error happens only with surefire and jacoco and nothing sonar related...

Marc R. Hoffmann

unread,
Jun 21, 2014, 3:12:55 AM6/21/14
to jac...@googlegroups.com
Hi,

- what exactly do you want to do (POM)?
- what is the error message you see?

Best regards,
-marc

Gurvan Le Dromaguet

unread,
Jun 23, 2014, 8:59:09 AM6/23/14
to jac...@googlegroups.com
Hi Marc, and thanks for your attention :)

I am trying to find a configuration of my project where when I run "mvn test", I have test results and also the "jacoco.exec" report file generated.
To be honest, yes, after that, I will ask Sonarqube to integrate this report, but for now there is no Sonarqube in the process.

Extract of my pom.xml :

... 
    <dependencies> 
  ...
     <dependency>
      <groupId>org.codehaus.sonar-plugins.java</groupId>
      <artifactId>sonar-jacoco-listeners</artifactId>
      <version>2.2.1</version>

      <scope>test</scope>
    </dependency>
  </dependencies>
... 
<plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.17</version>
        <executions>
          <execution>
            <id>default-test</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <redirectTestOutputToFile>true</redirectTestOutputToFile>
              <reuseForks>false</reuseForks>
              <excludes>
                <exclude>**/com/mycom/xxx/test/jms/*</exclude>
              </excludes>
              <argLine>${jacoco.agent.ut.arg}</argLine>

              <properties>
                <property>
                  <name>listener</name>
                  <value>org.sonar.java.jacoco.JUnitListener</value>
                </property>
              </properties>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <redirectTestOutputToFile>true</redirectTestOutputToFile>
          <reuseForks>false</reuseForks>
          <excludes>
            <exclude>**/com/mycom/etl/test/jms/*</exclude>
          </excludes>
          <argLine>${jacoco.agent.ut.arg}</argLine>

          <properties>
            <property>
              <name>listener</name>
              <value>org.sonar.java.jacoco.JUnitListener</value>
            </property>
          </properties>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.7.1.201405082137</version>
        <executions>
          <execution>
            <id>prepare-ut-agent</id>
            <phase>process-test-classes</phase>

            <goals>
              <goal>prepare-agent</goal>
            </goals>
            <configuration>
              <destFile>/home/xxx/dev/src/kernel/04.02/fflayer/target/jacoco.exec</destFile>
              <propertyName>jacoco.agent.ut.arg</propertyName>
              <append>true</append>
            </configuration>
          </execution>
          <execution>
            <id>prepare-it-agent</id>
            <phase>pre-integration-test</phase>

            <goals>
              <goal>prepare-agent</goal>
            </goals>
            <configuration>
              <destFile>/home/xxx/dev/src/kernel/04.02/fflayer/target/jacoco-it.exec</destFile>
              <propertyName>jacoco.agent.it.arg</propertyName>
              <append>true</append>
            </configuration>
          </execution>
        </executions>
      </plugin>

Ends up with:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 33.973s
[INFO] Finished at: Mon Jun 23 14:45:37 CEST 2014
[INFO] Final Memory: 22M/146M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test (default-test) on project xxx: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed: org.sonar.java.jacoco.JacocoController$JacocoControllerError: Unable to access JaCoCo Agent - make sure that you use JaCoCo and version not lower than 0.6.2. org/jacoco/agent/rt/RT: org.jacoco.agent.rt.RT -> [Help 1]


If I do the same, but deleting "reuseForks" option (ie getting back to default "true")

[INFO] --- jacoco-maven-plugin:0.7.1.201405082137:prepare-agent (prepare-ut-agent) @ fflayer ---
[INFO] jacoco.agent.ut.arg set to -javaagent:/home/xxx/.m2/repository/org/jacoco/org.jacoco.agent/0.7.1.201405082137/org.jacoco.agent-0.7.1.201405082137-runtime.jar=destfile=/home/gle_dromaguet/dev/src/kernel/04.02/fflayer/target/jacoco.exec,append=true
[INFO] 
[INFO] --- maven-surefire-plugin:2.17:test (default-test) @ fflayer ---
[INFO] Surefire report directory: /home/gle_dromaguet/dev/src/kernel/04.02/fflayer/target/surefire-reports
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running dil.flatfile2.FlatFileSetNameProviderTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.122 sec - in dil.flatfile2.FlatFileSetNameProviderTest
Running dil.flatfile2.FlatFileMappingTimePeriodTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.247 sec - in dil.flatfile2.FlatFileMappingTimePeriodTest
...

The Build is failed in the end because some of my JUnit are failed when reusefork is set as true
but it looks like the coverage has been working correctly this time ad the file "target/jacoco.exec" exists.

Do you have any idea what's going wrong ?

Regards,





--
You received this message because you are subscribed to a topic in the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jacoco/NlOKWfXD6sA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marc R. Hoffmann

unread,
Jun 23, 2014, 10:08:22 AM6/23/14
to jac...@googlegroups.com
Hi Gurvan,

look at your first dependency. The listener is provided by SonarSource. If you look at your stacktrace you will also see that the Exception comes from org.sonar.*

We do not maintain this listener here at JaCoCo. To get support for this you really need to check with the Sonar project. We cannot provide support for 3rd party integrations here.

Sorry,
-marc
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.

Gurvan Le Dromaguet

unread,
Jun 23, 2014, 11:03:11 AM6/23/14
to jac...@googlegroups.com
Ouch ... I have really been blind here. I see now this listener is not directly for coverage computation, but for SonarQube to have the code higlighted covered/not covered.
Thanks again. 

Gurvan Le Dromaguet

unread,
Jun 23, 2014, 11:27:38 AM6/23/14
to jac...@googlegroups.com
I confirm if I delete the use of this dependency, everything is ok.

smileso...@gmail.com

unread,
Apr 30, 2016, 1:05:00 AM4/30/16
to JaCoCo and EclEmma Users, gurv...@gmail.com
Hi ,
I want to integrate the coverage report(through external scripts not through JUNIT) generated by the Eclemma in Eclipse Tools(Coverage Tab) to be exported to the SonarCube. Do you have a write up to follow?

Regards
Pradeep
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages