Another Cryptic Message from Maven

I am still struggling with the development (and most of all, the tests) of a Maven plug-in. After I tried to run unit tests in my Eclipse, I got the following error.


java.lang.Exception: Unexpected exception, expected but was
at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:31)
at org.apache.maven.plugin.testing.MojoRule$2.evaluate(MojoRule.java:308)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:47)
at org.junit.rules.RunRules.evaluate(RunRules.java:18)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException
role: org.apache.maven.plugin.Mojo
roleHint: net.roboconf:roboconf-maven-plugin:1.0-SNAPSHOT:validate
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:264)
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:240)
at org.codehaus.plexus.PlexusTestCase.lookup(PlexusTestCase.java:205)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.lookupMojo(AbstractMojoTestCase.java:389)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.lookupMojo(AbstractMojoTestCase.java:334)
at org.apache.maven.plugin.testing.MojoRule.lookupMojo(MojoRule.java:164)
at net.roboconf.maven.ValidateMojoTest.testInvalidProject(ValidateMojoTest.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:22)
... 18 more
Caused by: java.util.NoSuchElementException
at java.util.Collections$EmptyIterator.next(Collections.java:3006)
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:260)
... 33 more

What matters here, is…

role: org.apache.maven.plugin.Mojo
roleHint: net.roboconf:roboconf-maven-plugin:1.0-SNAPSHOT:validate

What happened with my plug-in is that I had cleaned my Maven project.
After executing mvn clean test -X, I noticed the maven-plugin-plugin generates a descriptor from my mojos. The org.apache.maven.plugin.Mojo role is generated during this step. The role-hint is generated from my mojos. When I cleaned my project, I simply deleted the descriptor, which resulted in the error above.

After a refresh in Eclipse, I could go farther in my unit tests.
Conclusion: if you want to run the unit tests of your Maven plug-in in Eclipse, make sure it was compiled with Maven first.


About this entry