Getting "ClassNotFoundException: org.jacoco.agent.rt.internal_9dd1198.PreMain" with 1.7's Jacoco plugin


(jbisotti) #1

I’m attempting to replace Cobertura with Jacoco in our build. I’ve removed all the Cobertura references and I’ve added the following in their place: root.build.gradle

...
    subprojects {
        ...
        apply plugin: 'jacoco'
        jacoco { toolVersion = '0.6.3.201306030806' }
        ...
    }
    ...
    jacocoTestReport {
        // TODO: Temporary work-around -- http://issues.gradle.org/browse/GRADLE-2764
        additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
          reports {
            html.enabled false
            xml.enabled true
        }
    }
    ...

This works fine when I was testing it with

./gradlew test jacocoTestReport

However, when I switched to

./gradlew build jacocoTestReport

and my integration tests came into place, I started getting the following failure:

14:28:50.286 [INFO] [org.gradle.process.internal.DefaultExecHandle] Successfully started process 'Gradle Worker 16'
14:28:50.528 [ERROR] [system.err] Exception in thread "main" java.lang.ClassNotFoundException: org.jacoco.agent.rt.internal_9dd1198.PreMain
14:28:50.528 [ERROR] [system.err]
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
14:28:50.529 [QUIET] [system.out] FATAL ERROR in native method: processing of -javaagent failed
14:28:50.529 [ERROR] [system.err]
at java.security.AccessController.doPrivileged(Native Method)
14:28:50.529 [ERROR] [system.err]
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
14:28:50.530 [ERROR] [system.err]
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
14:28:50.530 [ERROR] [system.err]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
14:28:50.530 [ERROR] [system.err]
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
14:28:50.530 [ERROR] [system.err]
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:280)
14:28:50.530 [ERROR] [system.err]
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:338)
14:28:50.908 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED
14:28:50.908 [INFO] [org.gradle.process.internal.DefaultExecHandle] Process 'Gradle Worker 16' finished with exit value 134 (state: FAILED)
14:28:50.910 [ERROR] [org.gradle.messaging.actor.internal.DefaultActorFactory$NonBlockingActor] Process 'Gradle Worker 16' finished with non-zero exit value 134
org.gradle.process.internal.ExecException: Process 'Gradle Worker 16' finished with non-zero exit value 134
 at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:362)
 at org.gradle.process.internal.DefaultWorkerProcess.onProcessStop(DefaultWorkerProcess.java:89)
 at org.gradle.process.internal.DefaultWorkerProcess.access$000(DefaultWorkerProcess.java:33)
 at org.gradle.process.internal.DefaultWorkerProcess$1.executionFinished(DefaultWorkerProcess.java:55)
 at sun.reflect.GeneratedMethodAccessor431.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
 at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
 at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:81)
 at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:30)
 at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
 at com.sun.proxy.$Proxy42.executionFinished(Unknown Source)
 at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:212)
 at org.gradle.process.internal.DefaultExecHandle.finished(DefaultExecHandle.java:309)
 at org.gradle.process.internal.ExecHandleRunner.completed(ExecHandleRunner.java:108)
 at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:88)
 at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
 at java.lang.Thread.run(Thread.java:680)

Jacoco multiproject build can't load jacocoAgent
(jbisotti) #2

Has anyone seen anything like this or have any suggestions?


(jbisotti) #3

I finally came back to this and figured it out. Turns out it’s another manifestation of a known issue – GRADLE-2859. Specifying

systemProperties['user.dir'] = workingDir

fixed the issue.