vanniktech/gradle-android-junit-jacoco-plugin

Problems with outputting merged reports and updating JaCoCo version

KChernenko opened this issue · 19 comments

Hi! First of all thanks for the plugin - I've found that it's the only one that actually works for me.
However, I faced with several problems (because of a multi-module project) which I can't solve.

  1. Task jacocoTestReportMerged (after executing ./gradlew clean jacocoTestReport mergeJacocoReports jacocoTestReportMerged) fails with the following stacktrace:
Caused by: java.lang.IllegalStateException: Can't add different class with same name: com/gen/bettermeditation/utils/preferences/NameOfTheClass
        at org.jacoco.core.analysis.CoverageBuilder.visitCoverage(CoverageBuilder.java:106)
        at org.jacoco.core.analysis.Analyzer$1.visitEnd(Analyzer.java:92)
        at org.objectweb.asm.ClassVisitor.visitEnd(ClassVisitor.java:317)
        at org.jacoco.core.internal.flow.ClassProbesAdapter.visitEnd(ClassProbesAdapter.java:133)
        at org.objectweb.asm.ClassReader.accept(ClassReader.java:697)
        at org.objectweb.asm.ClassReader.accept(ClassReader.java:506)
        at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:107)
        at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:142)

If I exclude NameOfTheClass.class through the excludes in the module config, I'll get another fail with another class and so on. This happens only with jacocoTestReportMerged task but not with mergeJacocoReports.

  1. I want to use a newer version of the JaCoCo, because it possibly works better with Kotlin (related items: this and this). However, if I override configs in each module with, for example, version 0.8.1 my build (./gradlew clean jacocoTestReport mergeJacocoReports) will fail with the following stacktrace:
Caused by: java.io.IOException: Incompatible version 1007.
        at org.jacoco.core.data.ExecutionDataReader.readHeader(ExecutionDataReader.java:127)
        at org.jacoco.core.data.ExecutionDataReader.readBlock(ExecutionDataReader.java:107)
        at org.jacoco.core.data.ExecutionDataReader.read(ExecutionDataReader.java:87)
        at org.jacoco.core.tools.ExecFileLoader.load(ExecFileLoader.java:59)
        at org.jacoco.ant.MergeTask.load(MergeTask.java:85)
        ... 61 more

Am I doing something wrong?

Can you change ./gradlew clean jacocoTestReport mergeJacocoReports jacocoTestReportMerged to ./gradlew jacocoTestReportMerged and see whether that fixes your issue?

The second case is interesting. Which Gradle version are you using?

  1. Unfortunately ./gradlew jacocoTestReportMerged does not fixed the issue - I'm still getting Caused by: java.lang.IllegalStateException: Can't add different class with same name
  2. Gradle wrapper version is 4.8.1 and the plugin version is 3.1.3

Is NameOfTheClass duplicated? Otherwise why is it complaining?

I've not tried JaCoCo 0.8.1 myself. But the exception is coming from JaCoCo so something must be wrong

Nope. It could be even an Application class. Maybe it somehow connected with Kotlin? I have a companion object in the Application class or the case when we can place an interface and it's implementation in the same file (NameOfTheClass.kt: NameOfTheClass interface and NameOfTheClassImpl class). The stacktrace was pointing to such classes.

Could be. Do you have any repo where I can toy around with it? Otherwise it's hard for me to take any actions.

404 not found :/

Sorry, my bad - forgot to make it public.

Seems super weird since you essentially don't have any tests at all.

./gradlew jacocoTestReport succeeds

Merging likely fails since there's nothing to merge.

I've added several simple tests and merge task is still failing :(

./gradlew mergeJacocoReports seems to work in my case. Dunno what's wrong with jacocoTestReportMerged

iffa commented

I've also bumped into this issue (or at least a similar one) when setting JaCoCo version to 0.8.x for better Kotlin support.

Tried mergeJacocoReports, jacocoTestReportMerged pretty much anything I could come up with. Nothing seems to work, everything fails with the same exception:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':mergeJacocoReports'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipCachedTaskExecuter.execute(SkipCachedTaskExecuter.java:105)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ResolveBuildCacheKeyExecuter.execute(ResolveBuildCacheKeyExecuter.java:79)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
        at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
        at org.gradle.execution.taskgraph.LocalTaskInfoExecutor.execute(LocalTaskInfoExecutor.java:42)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:277)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:262)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:135)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:130)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.execute(DefaultTaskPlanExecutor.java:200)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.executeWithWork(DefaultTaskPlanExecutor.java:191)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.run(DefaultTaskPlanExecutor.java:130)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: : Unable to read C:\Users\----\StudioProjects\--------\data\build\jacoco\test.exec
        at org.jacoco.ant.MergeTask.load(MergeTask.java:87)
        at org.jacoco.ant.MergeTask.execute(MergeTask.java:67)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(BasicAntBuilder.java:78)
        at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:479)
        at org.gradle.internal.metaobject.BeanDynamicObject.tryInvokeMethod(BeanDynamicObject.java:191)
        at org.gradle.internal.metaobject.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:160)
        at org.gradle.api.internal.project.antbuilder.AntBuilderDelegate.nodeCompleted(AntBuilderDelegate.java:118)
        at org.gradle.internal.jacoco.AntJacocoMerge$1.doCall(AntJacocoMerge.java:46)
        at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:71)
        at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:53)
        at org.gradle.api.internal.project.antbuilder.DefaultIsolatedAntBuilder$2.execute(DefaultIsolatedAntBuilder.java:152)
        at org.gradle.api.internal.project.antbuilder.DefaultIsolatedAntBuilder$2.execute(DefaultIsolatedAntBuilder.java:134)
        at org.gradle.api.internal.project.antbuilder.ClassPathToClassLoaderCache.withCachedClassLoader(ClassPathToClassLoaderCache.java:134)
        at org.gradle.api.internal.project.antbuilder.DefaultIsolatedAntBuilder.execute(DefaultIsolatedAntBuilder.java:128)
        at org.gradle.internal.jacoco.AntJacocoMerge.execute(AntJacocoMerge.java:37)
        at org.gradle.testing.jacoco.tasks.JacocoMerge.merge(JacocoMerge.java:91)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:46)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:801)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:768)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:131)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:120)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:99)
        ... 33 more
Caused by: java.io.IOException: Incompatible version 1007.
        at org.jacoco.core.data.ExecutionDataReader.readHeader(ExecutionDataReader.java:127)
        at org.jacoco.core.data.ExecutionDataReader.readBlock(ExecutionDataReader.java:107)
        at org.jacoco.core.data.ExecutionDataReader.read(ExecutionDataReader.java:87)
        at org.jacoco.core.tools.ExecFileLoader.load(ExecFileLoader.java:59)
        at org.jacoco.ant.MergeTask.load(MergeTask.java:85)
        ... 64 more

AS 3.2-rc3, Gradle wrapper 4.10.

I'll gladly provide more info if needed.

We have the same issue. I couldn't figure out a solution for this, yet.

I'm not using JaCoCo 0.8+ yet. Is there something that Gradle needs to do? This plugin only forwards to those tasks / API provided by Gradle.

iffa commented

I don't know. Glancing over Gradle docs I see that Gradle by default already uses JaCoCo 0.8.x. The stacktrace is not really helpful either...

I found the problem and created a PR #128

Hi! I am getting this issue when using latest version (0.13.0).
Caused by: java.lang.IllegalStateException: Can't add different class with same name: com/datepickerexample/MainApplication$1
Is there anything I can try?

Nevermind: Added some files to excluded and got it to pass

cwliu commented

Hi! I am getting this issue when using latest version (0.13.0).
Caused by: java.lang.IllegalStateException: Can't add different class with same name: com/datepickerexample/MainApplication$1
Is there anything I can try?

Nevermind: Added some files to excluded and got it to pass

I had a similar issue when I was using 0.13.0. It was resolved after I use the latest 0.14.0-SNAPSHOT version.