Straightforward Jacoco setup fails to find "internal_e5875b2/Offline" classes

235 views
Skip to first unread message

David Karr

unread,
Jan 22, 2017, 3:57:44 PM1/22/17
to JaCoCo and EclEmma Users
Using the information at https://github.com/powermock/powermock/wiki/Code-coverage-with-JaCoCo and the offline example it links to, I set up jacoco in my largish maven multiproject build.  The build has an overall parent pom that all the child modules inherit from, and there is a separate aggregator pom.  I put the settings for jacoco in the parent pom.

The following is a paraphrased view of the parent pom, with some elements removed that I believe are irrelevant:
<?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>
   
<properties>
       
<maven.compiler.target>1.8</maven.compiler.target>
       
<maven.compiler.source>1.8</maven.compiler.source>
       
<junit.version>4.11</junit.version>
       
<mockito.version>1.10.19</mockito.version>
       
<powermock.version>1.6.6</powermock.version>
   
</properties>
   
<dependencyManagement>
       
<dependencies>
           
<dependency>
               
<groupId>junit</groupId>
               
<artifactId>junit</artifactId>
               
<version>${junit.version}</version>
               
<scope>test</scope>
           
</dependency>
           
<dependency>
               
<groupId>org.mockito</groupId>
               
<artifactId>mockito-core</artifactId>
               
<version>${mockito.version}</version>
               
<scope>test</scope>
           
</dependency>
           
<dependency>
               
<groupId>org.powermock</groupId>
               
<artifactId>powermock-module-junit4</artifactId>
               
<version>${powermock.version}</version>
               
<scope>test</scope>
           
</dependency>
           
<dependency>
               
<groupId>org.powermock</groupId>
               
<artifactId>powermock-api-mockito</artifactId>
               
<version>${powermock.version}</version>
               
<scope>test</scope>
           
</dependency>
       
</dependencies>
   
</dependencyManagement>

   
<dependencies>
       
<dependency>
           
<groupId>junit</groupId>
           
<artifactId>junit</artifactId>
           
<scope>test</scope>
       
</dependency>
       
<dependency>
           
<groupId>org.mockito</groupId>
           
<artifactId>mockito-core</artifactId>
           
<scope>test</scope>
       
</dependency>
       
<dependency>
           
<groupId>org.powermock</groupId>
           
<artifactId>powermock-module-junit4</artifactId>
           
<scope>test</scope>
       
</dependency>
       
<dependency>
           
<groupId>org.powermock</groupId>
           
<artifactId>powermock-api-mockito</artifactId>
           
<scope>test</scope>
       
</dependency>
       
<dependency>
           
<groupId>org.apache.maven.surefire</groupId>
           
<artifactId>surefire-junit4</artifactId>
           
<version>2.19.1</version>
           
<scope>test</scope>
       
</dependency>
   
</dependencies>
   
<build>
       
<plugins>
       
</plugins>
       
<pluginManagement>
           
<plugins>
           
<plugin>
               
<groupId>org.jacoco</groupId>
               
<artifactId>jacoco-maven-plugin</artifactId>
               
<version>0.7.8</version>
               
<executions>
                   
<execution>
                       
<id>default-instrument</id>
                       
<goals>
                           
<goal>instrument</goal>
                       
</goals>
                       
<configuration>
                         
<dataFile>${project.build.directory}/coverage.exec</dataFile>
                       
</configuration>
                   
</execution>
                   
<execution>
                       
<id>default-restore-instrumented-classes</id>
                       
<goals>
                           
<goal>restore-instrumented-classes</goal>
                       
</goals>
                   
</execution>
                   
<execution>
                       
<id>report</id>
                       
<phase>prepare-package</phase>
                       
<goals>
                           
<goal>report</goal>
                       
</goals>
                   
</execution>
               
</executions>
           
</plugin>
               
<plugin>
                   
<groupId>org.apache.maven.plugins</groupId>
                   
<artifactId>maven-surefire-plugin</artifactId>
                   
<version>2.19.1</version>
                   
<configuration>
                       
<forkCount>3</forkCount>
                       
<aggregate>true</aggregate>
                       
<reuseForks>true</reuseForks>
                       
<argLine>-Xmx1024m</argLine>
                       
<testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory>
                       
<includes>
                           
<include>**/*Test.java</include>
                       
</includes>
                       
<systemPropertyVariables>
                         
<jacoco-agent.destfile>${project.build.directory}/coverage.exec</jacoco-agent.destfile>
                       
</systemPropertyVariables>
                   
</configuration>
               
</plugin>
           
</plugins>
       
</pluginManagement>
   
</build>
</project>

When I run the build at the top-level, or in one of the child modules, I see every test failing with the following:
java.lang.NoClassDefFoundError: org/jacoco/agent/rt/internal_e5875b2/Offline

Any ideas what might be wrong here?

Evgeny Mandrikov

unread,
Jan 23, 2017, 2:42:27 AM1/23/17
to JaCoCo and EclEmma Users
As stated on page http://www.jacoco.org/jacoco/trunk/doc/offline.html : "Unlike with on-the-fly instrumentation offline instrumented classes get a direct dependency on the JaCoCo runtime."


<dependency>
  <groupId>org.jacoco</groupId>
  <artifactId>org.jacoco.agent</artifactId>
  <version>${jacoco.version}</version>
  <classifier>runtime</classifier>
</dependency>

David Karr

unread,
Jan 30, 2017, 3:01:09 PM1/30/17
to JaCoCo and EclEmma Users
On Sunday, January 22, 2017 at 11:42:27 PM UTC-8, Evgeny Mandrikov wrote:
As stated on page http://www.jacoco.org/jacoco/trunk/doc/offline.html : "Unlike with on-the-fly instrumentation offline instrumented classes get a direct dependency on the JaCoCo runtime."


<dependency>
  <groupId>org.jacoco</groupId>
  <artifactId>org.jacoco.agent</artifactId>
  <version>${jacoco.version}</version>
  <classifier>runtime</classifier>
</dependency>

I'm still having trouble with this, even though I've added this dependency.

Here is an excerpt of my build output:
[INFO] --- jacoco-maven-plugin:0.7.8:instrument (default-instrument) @ usl-creditcheck-impl ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ usl-creditcheck-impl ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 32 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ usl-creditcheck-impl ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 31 source files to C:\users\dk068x\git\oce_usl\usl-parent\usl-creditcheck-impl\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ usl-creditcheck-impl ---

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running ...
Results :

Tests run: 70, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- jacoco-maven-plugin:0.7.8:restore-instrumented-classes (default-restore-instrumented-classes) @ usl-creditcheck-impl ---
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.8:report (default-report) @ usl-creditcheck-impl ---
[INFO] Skipping JaCoCo execution due to missing execution data file.

 Here is a segment of the effective pom:
  <dependencies>
...
   
<dependency>

     
<groupId>org.jacoco</groupId>
     
<artifactId>org.jacoco.agent</artifactId>

     
<version>0.7.8</version>
     
<classifier>runtime</classifier>

     
<scope>test</scope>
   
</dependency>
 
</dependencies>
 
<build>
   
<plugins>

     
<plugin>
       
<groupId>org.jacoco</groupId>
       
<artifactId>jacoco-maven-plugin</artifactId>
       
<version>0.7.8</version>
       
<executions>
         
<execution>
           
<id>default-instrument</id>
           
<goals>
             
<goal>instrument</goal>
           
</goals>
           
<configuration>

             
<dataFile>...\target/coverage.exec</dataFile>

           
</configuration>
         
</execution>
         
<execution>
           
<id>default-restore-instrumented-classes</id>
           
<goals>
             
<goal>restore-instrumented-classes</goal>
           
</goals>
         
</execution>
         
<execution>

           
<id>default-report</id>

           
<phase>prepare-package</phase>
           
<goals>
             
<goal>report</goal>
           
</goals>
         
</execution>
       
</executions>
     
</plugin>
     
<plugin>

       
<artifactId>maven-surefire-plugin</artifactId>
       
<version>2.19.1</version>

       
<executions>
         
<execution>
           
<id>default-test</id>
           
<phase>test</phase>
           
<goals>
             
<goal>test</goal>
           
</goals>
           
<configuration>
             
<argLine>-Xmx1024m</argLine>

             
<includes>
               
<include>**/*Test.java</include>
             
</includes>
             
<systemPropertyVariables>

               
<jacoco-agent.destfile>...\target/coverage.exec</jacoco-agent.destfile>
             
</systemPropertyVariables>
           
</configuration>
         
</execution>
       
</executions>
       
<configuration>
         
<argLine>-Xmx1024m</argLine>

         
<includes>
           
<include>**/*Test.java</include>
         
</includes>
         
<systemPropertyVariables>

           
<jacoco-agent.destfile>...\target/coverage.exec</jacoco-agent.destfile>
         
</systemPropertyVariables>
       
</configuration>
     
</plugin>
   
</plugins>
 
</build>
</project>

What am I missing?

David Karr

unread,
Jan 30, 2017, 3:24:08 PM1/30/17
to JaCoCo and EclEmma Users

It seems clear this has something to do with a disconnect on the name of the ".exec" file to use.  From my effective pom, I appear to be telling it to use "coverage.exec", but if I run with "-X" I see conflicting information that says it expects to find "jacoco.exec", like this:
[DEBUG] Configuring mojo 'org.jacoco:jacoco-maven-plugin:0.7.8:report' with basic configurator -->
[DEBUG]   (f) dataFile = ...\target\jacoco.exec
[DEBUG]   (f) outputDirectory = ...\target\site\jacoco
[DEBUG] -- end configuration --

[INFO] Skipping JaCoCo execution due to missing execution data file.

Evgeny Mandrikov

unread,
Jan 30, 2017, 3:44:01 PM1/30/17
to JaCoCo and EclEmma Users
Hi,

Notice that specification of "dataFile" in configuration for execution of "instrument" goal has no effect, because there is no such parameter - see http://www.jacoco.org/jacoco/trunk/doc/instrument-mojo.html

You need to specify "dataFile" for "report" goal.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages