Issue
I am trying to build a maven project but its giving me below error.
java.lang.NoClassDefFoundError: org/jacoco/core/runtime/AgentOptions
[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.7.9:prepare-agent (agent) on project app: Execution agent of goal org.jacoco:ja
coco-maven-plugin:0.7.9:prepare-agent failed: A required class was missing while executing org.jacoco:jacoco-maven-plugin:0.7.9:prepare-agent: org/jacoc
o/core/runtime/AgentOptions
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.jacoco:jacoco-maven-plugin:0.7.9
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/t/.m2/repository1/org/jacoco/jacoco-maven-plugin/0.7.9/jacoco-maven-plugin-0.7.9.jar
[ERROR] urls[1] = file:/C:/Users/t/.m2/repository1/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------
[ERROR] : org.jacoco.core.runtime.AgentOptions
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException
Even though I have jacoco-maven-plugin:0.7.9 & org.jacoco.core-0.7.9 in maven repo its giving this error.
I am using mvn clean install command to build the application . Further I also tried building with -U flag
Lastly, when I build it using -X option I see below stack trace
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (agent) @ ncso-app-pso ---
[DEBUG] Skipped remote request for org.jacoco:jacoco-maven-plugin:pom:0.7.9, already updated during this session.
[WARNING] The POM for org.jacoco:jacoco-maven-plugin:jar:0.7.9 is missing, no dependency information available
[DEBUG] Dependency collection stats: {ConflictMarker.analyzeTime=50400, ConflictMarker.markTime=25500, ConflictMarker.nodeCount=1, ConflictIdSorter.grap
hTime=7100, ConflictIdSorter.topsortTime=12700, ConflictIdSorter.conflictIdCount=1, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=
56700, ConflictResolver.conflictItemCount=1, DefaultDependencyCollector.collectTime=8846200, DefaultDependencyCollector.transformTime=181500}
[DEBUG] org.jacoco:jacoco-maven-plugin:jar:0.7.9:
[DEBUG] org.codehaus.plexus:plexus-utils:jar:1.1:runtime
[DEBUG] Created new class realm plugin>org.jacoco:jacoco-maven-plugin:0.7.9
[DEBUG] Importing foreign packages into class realm plugin>org.jacoco:jacoco-maven-plugin:0.7.9
[DEBUG] Imported: < maven.api
[DEBUG] Populating class realm plugin>org.jacoco:jacoco-maven-plugin:0.7.9
[DEBUG] Included: org.jacoco:jacoco-maven-plugin:jar:0.7.9
[DEBUG] Included: org.codehaus.plexus:plexus-utils:jar:1.1
[DEBUG] Configuring mojo org.jacoco:jacoco-maven-plugin:0.7.9:prepare-agent from plugin realm ClassRealm[plugin>org.jacoco:jacoco-maven-plugin:0.7.9, pa
rent: sun.misc.Launcher$AppClassLoader@5c647e05]
[WARNING] Error injecting: org.jacoco.maven.AgentMojo
java.lang.NoClassDefFoundError: org/jacoco/core/runtime/AgentOptions
at java.lang.Class.getDeclaredMethods0 (Native Method)
at java.lang.Class.privateGetDeclaredMethods (Class.java:2701)
at java.lang.Class.getDeclaredMethods (Class.java:1975)
at com.google.inject.spi.InjectionPoint.getInjectionPoints (InjectionPoint.java:688)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields (InjectionPoint.java:380)
at com.google.inject.internal.ConstructorBindingImpl.getInternalDependencies (ConstructorBindingImpl.java:164)
at com.google.inject.internal.InjectorImpl.getInternalDependencies (InjectorImpl.java:613)
at com.google.inject.internal.InjectorImpl.cleanup (InjectorImpl.java:569)
at com.google.inject.internal.InjectorImpl.initializeJitBinding (InjectorImpl.java:555)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding (InjectorImpl.java:884)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive (InjectorImpl.java:805)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding (InjectorImpl.java:282)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow (InjectorImpl.java:214)
at com.google.inject.internal.InjectorImpl.getProviderOrThrow (InjectorImpl.java:1006)
at com.google.inject.internal.InjectorImpl.getProvider (InjectorImpl.java:1038)
at com.google.inject.internal.InjectorImpl.getProvider (InjectorImpl.java:1001)
at com.google.inject.internal.InjectorImpl.getInstance (InjectorImpl.java:1051)
at org.eclipse.sisu.space.AbstractDeferredClass.get (AbstractDeferredClass.java:48)
at com.google.inject.internal.ProviderInternalFactory.provision (ProviderInternalFactory.java:81)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision (InternalFactoryToInitializableAdapter.java:53)
at com.google.inject.internal.ProviderInternalFactory$1.call (ProviderInternalFactory.java:65)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision (ProvisionListenerStackCallback.java:115)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision (ProvisionListenerStackCallback.java:133)
at com.google.inject.internal.ProvisionListenerStackCallback.provision (ProvisionListenerStackCallback.java:68)
at com.google.inject.internal.ProviderInternalFactory.circularGet (ProviderInternalFactory.java:63)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.get (InternalFactoryToInitializableAdapter.java:45)
at com.google.inject.internal.InjectorImpl$2$1.call (InjectorImpl.java:1016)
at com.google.inject.internal.InjectorImpl.callInContext (InjectorImpl.java:1092)
at com.google.inject.internal.InjectorImpl$2.get (InjectorImpl.java:1012)
at org.eclipse.sisu.inject.Guice4$1.get (Guice4.java:162)
at org.eclipse.sisu.inject.LazyBeanEntry.getValue (LazyBeanEntry.java:81)
at org.eclipse.sisu.plexus.LazyPlexusBean.getValue (LazyPlexusBean.java:51)
at org.codehaus.plexus.DefaultPlexusContainer.lookup (DefaultPlexusContainer.java:263)
at org.codehaus.plexus.DefaultPlexusContainer.lookup (DefaultPlexusContainer.java:255)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo (DefaultMavenPluginManager.java:519)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:124)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
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.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.lang.ClassNotFoundException: org.jacoco.core.runtime.AgentOptions
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass (SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass (ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass (ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass (ClassRealm.java:239)
at java.lang.Class.getDeclaredMethods0 (Native Method)
at java.lang.Class.privateGetDeclaredMethods (Class.java:2701)
at java.lang.Class.getDeclaredMethods (Class.java:1975)
at com.google.inject.spi.InjectionPoint.getInjectionPoints (InjectionPoint.java:688)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields (InjectionPoint.java:380)
at com.google.inject.internal.ConstructorBindingImpl.getInternalDependencies (ConstructorBindingImpl.java:164)
at com.google.inject.internal.InjectorImpl.getInternalDependencies (InjectorImpl.java:613)
at com.google.inject.internal.InjectorImpl.cleanup (InjectorImpl.java:569)
at com.google.inject.internal.InjectorImpl.initializeJitBinding (InjectorImpl.java:555)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding (InjectorImpl.java:884)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive (InjectorImpl.java:805)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding (InjectorImpl.java:282)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow (InjectorImpl.java:214)
at com.google.inject.internal.InjectorImpl.getProviderOrThrow (InjectorImpl.java:1006)
at com.google.inject.internal.InjectorImpl.getProvider (InjectorImpl.java:1038)
at com.google.inject.internal.InjectorImpl.getProvider (InjectorImpl.java:1001)
at com.google.inject.internal.InjectorImpl.getInstance (InjectorImpl.java:1051)
at org.eclipse.sisu.space.AbstractDeferredClass.get (AbstractDeferredClass.java:48)
at com.google.inject.internal.ProviderInternalFactory.provision (ProviderInternalFactory.java:81)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision (InternalFactoryToInitializableAdapter.java:53)
at com.google.inject.internal.ProviderInternalFactory$1.call (ProviderInternalFactory.java:65)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision (ProvisionListenerStackCallback.java:115)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision (ProvisionListenerStackCallback.java:133)
at com.google.inject.internal.ProvisionListenerStackCallback.provision (ProvisionListenerStackCallback.java:68)
at com.google.inject.internal.ProviderInternalFactory.circularGet (ProviderInternalFactory.java:63)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.get (InternalFactoryToInitializableAdapter.java:45)
at com.google.inject.internal.InjectorImpl$2$1.call (InjectorImpl.java:1016)
at com.google.inject.internal.InjectorImpl.callInContext (InjectorImpl.java:1092)
at com.google.inject.internal.InjectorImpl$2.get (InjectorImpl.java:1012)
at org.eclipse.sisu.inject.Guice4$1.get (Guice4.java:162)
at org.eclipse.sisu.inject.LazyBeanEntry.getValue (LazyBeanEntry.java:81)
at org.eclipse.sisu.plexus.LazyPlexusBean.getValue (LazyPlexusBean.java:51)
at org.codehaus.plexus.DefaultPlexusContainer.lookup (DefaultPlexusContainer.java:263)
at org.codehaus.plexus.DefaultPlexusContainer.lookup (DefaultPlexusContainer.java:255)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo (DefaultMavenPluginManager.java:519)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:124)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
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.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Solution
You can run the maven build command with argument -X
to enable debug logging.
With this output you now see the following line in your log:
[WARNING] The POM for org.jacoco:jacoco-maven-plugin:jar:0.7.9 is missing, no dependency information available
Normally the class AgentOptions
is loaded from org.jacoco.core
, which is a dependency of the plugin. But without the pom file, the maven build process doesn't know this and even though you have that jar file in your local repository, it will not be used due to the missing pom file.
In my local m2 i do have the following pom file: .m2\repository\org\jacoco\jacoco-maven-plugin\0.7.9\jacoco-maven-plugin-0.7.9.pom
. This leads me to believe there is something wrong with your downloaded copy.
I have verified this causes a problem by removing the dependencies
list in the local copy of the plugins' pom file, and then i get the same error message in the build process.
As a solution you can clear the contents of .m2\repository\org\jacoco\
and try your build again, then all correct plugin files and dependencies should be downloaded again from maven central.
We can also see [DEBUG] Skipped remote request for org.jacoco:jacoco-maven-plugin:pom:0.7.9, already updated during this session.
, this could indicate that there was a problem downloading the pom file. Are there any errors in .m2\repository\org\jacoco\jacoco-maven-plugin\0.7.9\_remote.repositories
?
Is it trying to download from central
, or do you have any custom pluginRepositories
that might not have the complete pom file? You can see your entire pom file by running mvn help:effective-pom
.
Normally that should include the following from the super pom:
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
More extreme measures could be to download a newer version of maven, or clear your entire local .m2
(create a backup if you have important files in there).
Those would be the places to look to resolve this issue.
Answered By - slindenau
Answer Checked By - David Marino (JavaFixing Volunteer)