java.lang.NoSuchMethodError:DefaultPlexusContainer

时间:2018-04-03 14:45:47

标签: java maven maven-plugin-testing-harness

我想使用maven-plugin-testing-harness,我将以下依赖项包含在我的项目中:

<dependency>
        <groupId>org.apache.maven.plugin-testing</groupId>
        <artifactId>maven-plugin-testing-harness</artifactId>
        <version>3.3.0</version>
        <scope>test</scope>
    </dependency>

我收到以下错误:

Running YourMojoTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.055 sec <<< FAILURE!
testMojoGoal(YourMojoTest)  Time elapsed: 0.017 sec  <<< ERROR!
java.lang.NoSuchMethodError: org.codehaus.plexus.DefaultPlexusContainer.<init>(Lorg/codehaus/plexus/ContainerConfiguration;[Lcom/google/inject/Module;)V
    at org.apache.maven.plugin.testing.AbstractMojoTestCase.setupContainer(AbstractMojoTestCase.java:264)
    at org.apache.maven.plugin.testing.AbstractMojoTestCase.getContainer(AbstractMojoTestCase.java:298)
    at org.apache.maven.plugin.testing.AbstractMojoTestCase.setUp(AbstractMojoTestCase.java:152)
    at YourMojoTest.setUp(YourMojoTest.java:13)
    at junit.framework.TestCase.runBare(TestCase.java:125)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    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:497)

我们如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

在testing-harness之前包含org.eclipse.sisu plexus依赖项会导致类加载器加载正确的DefaultPlexusContainer类。

 <dependency>
            <groupId>org.eclipse.sisu</groupId>
            <artifactId>org.eclipse.sisu.plexus</artifactId>
            <version>0.3.3</version>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.plugin-testing</groupId>
            <artifactId>maven-plugin-testing-harness</artifactId>
            <version>3.3.0</version>
            <scope>test</scope>
        </dependency>

这似乎有效。依赖关系的顺序很重要。