Andrzej Zabost
09/18/2025, 11:54 AMplugins {
id("jacoco")
// ... everything else
}
tasks.withType<Test> {
configure<JacocoTaskExtension> {
excludes = listOf(
"com.example.*",
)
}
}
but it doesn't seem to do anything.
I tried different formats, like com.example.**, com/example/* and com/example/**, but none of them worked.
How do I correctly do this?
Btw I'm running coverage from IDE by just executing a Gradle task with the coverage option.
I know I can edit the "run configuration" and add the excludes in the IDE's UI, but I'd rather have a global configuration in Gradle.Vampire
09/18/2025, 12:08 PMVampire
09/18/2025, 12:11 PMAndrzej Zabost
09/18/2025, 12:16 PMActually, in the project settings you can switch between using IJ coverage recording and JaCoCo coverage recordingAh, so that was the source of my problems. Just found this:
Andrzej Zabost
09/18/2025, 12:16 PMAndrzej Zabost
09/18/2025, 12:21 PMAndrzej Zabost
09/18/2025, 12:30 PM> Task :users:testDebugUnitTest
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:560)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:572)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.jacoco.agent.rt.internal_0e20598.core.runtime.InjectedClassRuntime$Lookup.defineClass(InjectedClassRuntime.java:134)
at org.jacoco.agent.rt.internal_0e20598.core.runtime.InjectedClassRuntime.startup(InjectedClassRuntime.java:54)
at org.jacoco.agent.rt.internal_0e20598.PreMain.premain(PreMain.java:50)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
... 3 more
Caused by: java.lang.LinkageError: loader 'bootstrap' attempted duplicate class definition for java.lang.$JaCoCo. (java.lang.$JaCoCo is in module java.base of loader 'bootstrap')
at java.base/java.lang.ClassLoader.defineClass0(Native Method)
at java.base/java.lang.System$2.defineClass(System.java:2406)
at java.base/java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClass(MethodHandles.java:2505)
at java.base/java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClass(MethodHandles.java:2480)
at java.base/java.lang.invoke.MethodHandles$Lookup.defineClass(MethodHandles.java:1865)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
... 8 more
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message Outstanding error when calling method in invokeJavaAgentMainMethod at src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 627
*** java.lang.instrument ASSERTION FAILED ***: "success" with message invokeJavaAgentMainMethod failed at src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 466
*** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 429
FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V [libjvm.dylib+0x525930] jni_FatalError+0x7c
V [libjvm.dylib+0x68d68c] JvmtiExport::post_vm_initialized()+0x2b8
V [libjvm.dylib+0xa245ac] Threads::create_vm(JavaVMInitArgs*, bool*)+0x6c8
V [libjvm.dylib+0x544298] JNI_CreateJavaVM+0x74
C [libjli.dylib+0xa228] JavaMain+0x100
C [libjli.dylib+0xd5b0] ThreadJavaMain+0xc
C [libsystem_pthread.dylib+0x6c0c] _pthread_start+0x88
> Task :users:testDebugUnitTest FAILEDVampire
09/18/2025, 12:32 PM--info (or --debug if it is not there) you can have a look at the JVM args used.
I'd guess you now have the JaCoCo agent defined twice, once by the Gradle build and once injected by IJ and that does most probably not work.Vampire
09/18/2025, 12:32 PMVampire
09/18/2025, 12:33 PMVampire
09/18/2025, 12:34 PMAndrzej Zabost
09/18/2025, 12:52 PMVampire
09/18/2025, 12:55 PMVampire
09/18/2025, 12:56 PMVampire
09/18/2025, 12:56 PMVampire
09/18/2025, 1:07 PMVampire
09/18/2025, 1:08 PMAndrzej Zabost
09/18/2025, 1:44 PMIt might still be best to just not use "... with Coverage" but just let IJ display the JaCoCo report that Gradle created.Yeah, this works fine, but it's cumbersome to select the appropriate report file every time with the IDE's file picker, especially when there are many modules etc.
Vampire
09/18/2025, 2:03 PMidea.active), but then you will again not have the includes / excludes you define in the build script.