Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassNotFoundException for CloverCompilerAdapter when using OpenClover 4.3.1 on a Java project #125

Closed
bjornvester opened this issue Jan 17, 2019 · 6 comments
Assignees
Milestone

Comments

@bjornvester
Copy link

Running the cloverGenerateReport task on a simple Java project configured with version 2.2.1 of the plugin, and version 4.3.1 of OpenClover (both newest at the time of this writing) throws the following exception:

> Task :test FAILED
[clover-clean] OpenClover Version 4.3.1, built on September 21 2018 (build-1013)
[clover-setup] OpenClover Version 4.3.1, built on September 21 2018 (build-1013)
[clover-setup] Clover is enabled with initstring 'C:\Work\Playground\openclover\compiler-class-not-found\build/.clover/clover.db-test'
    [javac] : warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> Class not found: com.atlassian.clover.ant.taskdefs.CloverCompilerAdapter

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':test'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:95)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:91)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:119)
        at org.gradle.api.internal.tasks.execution.ResolvePreviousStateExecuter.execute(ResolvePreviousStateExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:93)
        at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:45)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:94)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:56)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:55)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:67)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:49)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:315)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:305)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:175)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:101)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:49)
        at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:43)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:355)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:134)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:129)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:202)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:193)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
        at java.lang.Thread.run(Thread.java:748)
Caused by: : Class not found: com.atlassian.clover.ant.taskdefs.CloverCompilerAdapter
        at org.apache.tools.ant.util.ClasspathUtils.newInstance(ClasspathUtils.java:255)
        at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.resolveClassName(CompilerAdapterFactory.java:198)
        at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:159)
        at org.apache.tools.ant.taskdefs.Javac.findSupportedFileExtensions(Javac.java:1220)
        at org.apache.tools.ant.taskdefs.Javac.scanDir(Javac.java:1157)
        at org.apache.tools.ant.taskdefs.Javac.collectFileListFromSourcePath(Javac.java:1188)
        at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:1124)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at groovy.util.AntBuilder.performTask(AntBuilder.java:338)
        at groovy.util.AntBuilder.nodeCompleted(AntBuilder.java:283)
        at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:154)
        at groovy.util.AntBuilder.doInvokeMethod(AntBuilder.java:218)
        at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:67)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:47)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:135)
        at com.bmuschko.gradle.clover.InstrumentCodeAction.compileJava(InstrumentCodeAction.groovy:332)
        at com.bmuschko.gradle.clover.InstrumentCodeAction.compileSrcFiles(InstrumentCodeAction.groovy:251)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:190)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:58)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:168)
        at com.bmuschko.gradle.clover.InstrumentCodeAction.compileClasses(InstrumentCodeAction.groovy:213)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:190)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:58)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:168)
        at com.bmuschko.gradle.clover.InstrumentCodeAction.instrumentCode(InstrumentCodeAction.groovy:135)
        at com.bmuschko.gradle.clover.InstrumentCodeAction.execute(InstrumentCodeAction.groovy:61)
        at com.bmuschko.gradle.clover.InstrumentCodeAction.execute(InstrumentCodeAction.groovy)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:704)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:671)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$2.run(ExecuteActionsTaskExecuter.java:284)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:301)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:293)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:175)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:273)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:258)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$200(ExecuteActionsTaskExecuter.java:67)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:145)
        at org.gradle.internal.execution.impl.steps.ExecuteStep.execute(ExecuteStep.java:49)
        at org.gradle.internal.execution.impl.steps.CancelExecutionStep.execute(CancelExecutionStep.java:34)
        at org.gradle.internal.execution.impl.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:69)
        at org.gradle.internal.execution.impl.steps.TimeoutStep.execute(TimeoutStep.java:49)
        at org.gradle.internal.execution.impl.steps.CatchExceptionStep.execute(CatchExceptionStep.java:33)
        at org.gradle.internal.execution.impl.steps.CreateOutputsStep.execute(CreateOutputsStep.java:50)
        at org.gradle.internal.execution.impl.steps.SnapshotOutputStep.execute(SnapshotOutputStep.java:43)
        at org.gradle.internal.execution.impl.steps.SnapshotOutputStep.execute(SnapshotOutputStep.java:29)
        at org.gradle.internal.execution.impl.steps.CacheStep.executeWithoutCache(CacheStep.java:134)
        at org.gradle.internal.execution.impl.steps.CacheStep.lambda$execute$3(CacheStep.java:83)
        at java.util.Optional.orElseGet(Optional.java:267)
        at org.gradle.internal.execution.impl.steps.CacheStep.execute(CacheStep.java:82)
        at org.gradle.internal.execution.impl.steps.CacheStep.execute(CacheStep.java:36)
        at org.gradle.internal.execution.impl.steps.PrepareCachingStep.execute(PrepareCachingStep.java:33)
        at org.gradle.internal.execution.impl.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:38)
        at org.gradle.internal.execution.impl.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:23)
        at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:96)
        at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:89)
        at java.util.Optional.map(Optional.java:215)
        at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:52)
        at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:36)
        at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:34)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:91)
        ... 35 more
Caused by: java.lang.ClassNotFoundException: com.atlassian.clover.ant.taskdefs.CloverCompilerAdapter
        at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1384)
        at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1333)
        at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1088)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at org.apache.tools.ant.util.ClasspathUtils.newInstance(ClasspathUtils.java:247)
        ... 111 more


* Get more help at https://help.gradle.org

BUILD FAILED in 2s
4 actionable tasks: 4 executed

I am using Java 8 and Gradle 5.1.1.

It looks like the plugin is not compatible with that version of OpenClover, likely due to the fix for https://bitbucket.org/openclover/clover/issues/75. In that issue, it states that a work-around is to add the OpenClover jar file to the lib folder for Ant, which is of cause not going to work in a Gradle plugin. So I have no idea how to fix this :(

The plugin works on the same project if I downgrade to OpenClover 4.2.1. It also works if the project only contains Groovy sources (and these get instrumented correctly as well).

Here is my Gradle build file for reference:

plugins {
    id 'java'
    id 'com.bmuschko.clover' version '2.2.1'
}

repositories {
    jcenter()
}

dependencies {
    testImplementation 'junit:junit:4.12'
    clover 'org.openclover:clover:4.3.1'
}
@Alex-Vol-SV
Copy link
Collaborator

I have to do some work for adding support for the 4.3.1 Clover. It includes support for Java 9+ which I would like to include. I cannot promise I will get to it soon, but I will try.

@Alex-Vol-SV Alex-Vol-SV self-assigned this Jan 17, 2019
@dlehammer
Copy link

@Alex-Vol-SV seems to be a classloader issue, most-likely similar to [4.3.1] Ant javac task is unable to find CloverCompilerAdapter class.
That issue seems to be connected to the OpenClover team adding support for Java 9.

They list a workaround:

Copy clover.jar to ANT_HOME\lib directory.

I've tried the workaround, but it doesn't seem to make a difference for gradle-clover-plugin.

Side-note

Initially I thought this would be a trivial upgrade for gradle-clover-plugin, mainly documentation-based, as I've tried OpenClover 4.3.1 successfully on Gradle/Groovy project w. gradle-clover-plugin 2.2.1.

But I can see that Java-tests fails with or without the suggested work-around from OpenClover :/

42 tests completed, 30 failed

JavaMultiProjectSpec. Build a Java multi-project (with Gradle Version 2.14.1)
JavaMultiProjectSpec. Build a Java multi-project (with Gradle Version 3.5.1)
JavaMultiProjectSpec. Build a Java multi-project (with Gradle Version 4.4.1)
JavaMultiProjectWithEarSpec. Build a Java multi-project with instrumented JARs in an EAR (with Gradle Version 2.14.1)
JavaMultiProjectWithEarSpec. Build a Java multi-project with instrumented JARs in an EAR (with Gradle Version 3.5.1)
JavaMultiProjectWithEarSpec. Build a Java multi-project with instrumented JARs in an EAR (with Gradle Version 4.4.1)
JavaMultiTestTaskProjectSpec. Build a Java multi-test-task project except test
JavaMultiTestTaskProjectSpec. Build a Java multi-test-task project for all tasks
JavaMultiTestTaskProjectSpec. Build a Java multi-test-task project only for test
JavaProjectGroovyTestsSpec. Build a Java project with Groovy Tests (with Gradle Version 2.14.1)
JavaProjectGroovyTestsSpec. Build a Java project with Groovy Tests (with Gradle Version 3.5.1)
JavaProjectGroovyTestsSpec. Build a Java project with Groovy Tests (with Gradle Version 4.4.1)
JavaProjectLambdasSpec. Build a Java project with lambdas (with Gradle Version 2.14.1)
JavaProjectLambdasSpec. Build a Java project with lambdas (with Gradle Version 3.5.1)
JavaProjectLambdasSpec. Build a Java project with lambdas (with Gradle Version 4.4.1)
JavaProjectSpec. Build a Java project (with Gradle Version 2.14.1)
JavaProjectSpec. Build a Java project (with Gradle Version 3.5.1)
JavaProjectSpec. Build a Java project (with Gradle Version 4.4.1)
JavaProjectWithAdditionalTestsSpec. Build a Java project with additional tests (with Gradle Version 2.14.1)
JavaProjectWithAdditionalTestsSpec. Build a Java project with additional tests (with Gradle Version 3.5.1)
JavaProjectWithAdditionalTestsSpec. Build a Java project with additional tests (with Gradle Version 4.4.1)
JavaProjectWithMethodFiltersSpec. Build a Java project with method filters (with Gradle Version 2.14.1)
JavaProjectWithMethodFiltersSpec. Build a Java project with method filters (with Gradle Version 3.5.1)
JavaProjectWithMethodFiltersSpec. Build a Java project with method filters (with Gradle Version 4.4.1)
JavaTestOptSpec. Build a Java project with test optimization enabled (with Gradle Version 2.14.1)
JavaTestOptSpec. Build a Java project with test optimization enabled (with Gradle Version 3.5.1)
JavaTestOptSpec. Build a Java project with test optimization enabled (with Gradle Version 4.4.1)
SpringProjectWithCloverSpec. Build a Java Spring project with debug mode enabled (with Gradle Version 2.14.1)
SpringProjectWithCloverSpec. Build a Java Spring project with debug mode enabled (with Gradle Version 3.5.1)
SpringProjectWithCloverSpec. Build a Java Spring project with debug mode enabled (with Gradle Version 4.4.1)

Any hints? :)

@Alex-Vol-SV
Copy link
Collaborator

I know where this has to change. I will have to add the clover jar to the classpath instead of the bootclasspath. Prior to Java 9 this was the preferred way but now it must be in the compiler classpath.

@dlehammer
Copy link

@Alex-Vol-SV wrote

I will have to add the clover jar to the classpath instead of the bootclasspath

Thanks for the hint :)
I've poked around in the source-code, but I've been unable to pinpoint where bootclasspath is configured for Ant javac in gradle-clover-plugin.

Snippets from InstrumentCodeAction.groovy referencing javac.

Line 309

                ant.javac(source: getSourceCompatibility(), target: getTargetCompatibility(), encoding: getEncoding(),
                          debug: getDebug()) {

Note: adding classpath here doesn't solve this issue.

Line 331

            ant.javac(destdir: destDir.canonicalPath, source: getSourceCompatibility(), target: getTargetCompatibility(),
                  classpath: classpath, encoding: getEncoding(), executable: getExecutable(), debug: getDebug()) {

Of all the references I've reviewed, the above seems to be the most-likely regarding the Java issue, unfortunately it already references classpath not "boot".

FYI: #125 and #119 seems to share symptom.

@Alex-Vol-SV
Copy link
Collaborator

I tried a few things and this still is not solved. Injecting the Clover JAR in the correct classpath is not as easy as I thought. I will keep trying to see if there is a way to solve this without major overhaul.

@Alex-Vol-SV
Copy link
Collaborator

I was able to get this to work by enabling the javac includeAntRuntime flag and adding clover.jar in the $HOME/.ant/lib directory of the system. I am very much against such a solution but I may resort to enabling this as a new clover configuration so users can choose to use it if they find it acceptable.

I will continue looking for a better answer because this is rather awkward to implement in a CI system. I would hesitate to force every build slave in a CI to have preinstalled copies of Clover JAR everywhere.

@Alex-Vol-SV Alex-Vol-SV added this to the 2.2.2 milestone Feb 19, 2019
Alex-Vol-SV added a commit that referenced this issue Feb 20, 2019
The trick was to install clover JAR directly into the Ant
package classloader. That is cheating but it works.
Alex-Vol-SV added a commit that referenced this issue Feb 20, 2019
The trick was to install clover JAR directly into the Ant
package classloader. That is cheating but it works.
@Alex-Vol-SV Alex-Vol-SV added Fixed and removed Fixed labels Feb 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants