Jacoco multiproject build can't load jacocoAgent

I’m beating my head against a problem with Gradle and Jacoco - far as I can tell my use case is very similar, I just want to generate a coverage report for a multiproject. I can run the command below from an individual module without any problems, but when I run it from root it goes bang.

Ultimately I want to publish the data to Sonar, but I can’t get the jacocoTestReport to work, so that’s going nowhere :smile:

I’ve read all the posts I can find that seem to be related, like Getting “ClassNotFoundException: org.jacoco.agent.rt.internal_9dd1198.PreMain” with 1.7’s Jacoco plugin, and tried their solutions, but nothing works.

Using:

  • Gradle 2.6
  • JDK 1.7.0_79
  • Mac OS X

Snippet from my project:

build.gradle

subprojects {
apply from: file("${rootDir}/gradle/jacoco.gradle")
}

jacoco.gradle:

apply plugin: ‘jacoco’

test {
systemProperties[‘user.dir’] = workingDir
}

Command line: “./gradlew test jacocoTestReport”

Output:

Exception in thread “main” java.lang.ClassNotFoundException: org.jacoco.agent.rt.internal_932a715.PreMain
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
FATAL ERROR in native method: processing of -javaagent failed
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:300)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:397)

I’m running into exactly the same issue using the same build setup. Any progress on this issue?

These are the versions I use:

  • Gradle 2.8
  • JDK 1.8.0_31
  • Mac OS X 10.11.1

Found the problem for my project.

systemProperties were already overridden, so I had to put systemProperties['user.dir'] = workingDir in the correct location:

tasks.withType(Test) {
    systemProperties = System.properties
    systemProperties['user.dir'] = workingDir
}