AssertionFailedError:需要Maven 3.2.4或更高版本(运行版本3.2.5)

时间:2017-05-17 00:21:06

标签: java maven junit maven-plugin maven-surefire-plugin

在Maven中,我正在尝试使用单元测试(使用maven-surefire-plugin)构建我的自定义插件,但是我收到以下错误:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.aaa.bbb.maven.plugin.eee.dddTest
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.038 sec <<< FAILURE!
testSomething(com.aaa.bbb.maven.plugin.eee.dddTest)  Time elapsed: 0.009 sec  <<< FAILURE!
junit.framework.AssertionFailedError: Maven 3.2.4 or better is required
    at junit.framework.Assert.fail(Assert.java:47)
    at junit.framework.Assert.assertTrue(Assert.java:20)
    at org.apache.maven.plugin.testing.AbstractMojoTestCase.setUp(AbstractMojoTestCase.java:149)
    at com.aaa.bbb.maven.plugin.eee.dddTest.setUp(dddTest.java:40)
    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:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:95)
    at org.apache.maven.surefire.junit.JUnit3Provider.executeTestSet(JUnit3Provider.java:121)
    at org.apache.maven.surefire.junit.JUnit3Provider.invoke(JUnit3Provider.java:98)
    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.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)


Results :

Failed tests:   testSomething(com.aaa.bbb.maven.plugin.eee.dddTest): Maven 3.2.4 or better is required

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.950 s

重要的是:

junit.framework.AssertionFailedError: Maven 3.2.4 or better is required

但是当我查看版本时,我看到了:

$ mvn -version
Apache Maven 3.2.5

如果我使用-DskipTests跳过测试,那么它的构建正常。为什么会发生这种错误?也许我使用的依赖是Maven 3.2.5?为什么它没有检测到正确的版本?

任何帮助/建议都会非常有用。

P.S。在我添加了一个特定的mojo之后,这个错误就开始了。如果我删除了Mojo,它正在建设中。 Mojo可能会导致什么?

<小时/> 修改

我从Setup()删除了dddTest.java,但我仍然遇到同样的错误,只是没有指定该行。新错误:

junit.framework.AssertionFailedError: Maven 3.2.4 or better is required
    at junit.framework.Assert.fail(Assert.java:47)
    at junit.framework.Assert.assertTrue(Assert.java:20)
    at org.apache.maven.plugin.testing.AbstractMojoTestCase.setUp(AbstractMojoTestCase.java:149)
    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:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:95)
    at org.apache.maven.surefire.junit.JUnit3Provider.executeTestSet(JUnit3Provider.java:121)
    at org.apache.maven.surefire.junit.JUnit3Provider.invoke(JUnit3Provider.java:98)
    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.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

有什么想法吗?

<小时/> 编辑2:

我看到问题Django Documetation并且我意识到依赖版本存在一些问题。所以我更新了链接上提到的maven依赖项的版本,然后更新了一些(基于将依赖树与maven中心进行比较)。每次更新版本时,错误都会更改(但在测试期间仍会发生)。现在我面临以下错误:

java.lang.NoSuchMethodError: org.codehaus.plexus.ContainerConfiguration.setClassPathScanning(Ljava/lang/String;)Lorg/codehaus/plexus/ContainerConfiguration;
    at org.apache.maven.plugin.testing.AbstractMojoTestCase.setupContainerConfiguration(AbstractMojoTestCase.java:285)
    at org.apache.maven.plugin.testing.AbstractMojoTestCase.setupContainer(AbstractMojoTestCase.java:259)
    at org.apache.maven.plugin.testing.AbstractMojoTestCase.getContainer(AbstractMojoTestCase.java:298)
    at org.apache.maven.plugin.testing.AbstractMojoTestCase.setUp(AbstractMojoTestCase.java:152)
    at com.aaa.bbb.maven.plugin.eee.dddTest.setUp(dddTest.java:39)
    at junit.framework.TestCase.runBare(TestCase.java:139)
    at junit.framework.TestResult$1.protect(TestResult.java:122)
    at junit.framework.TestResult.runProtected(TestResult.java:142)

此错误的依赖关系树:

+- org.apache.maven.plugin-tools:maven-plugin-annotations:jar:3.5:provided
 +- org.apache.maven.plugin-testing:maven-plugin-testing-harness:jar:3.3.0:test
 |  +- commons-io:commons-io:jar:2.2:compile
 |  \- org.codehaus.plexus:plexus-archiver:jar:2.2:test
 |     \- org.codehaus.plexus:plexus-io:jar:2.0.4:test
 +- org.apache.maven:maven-artifact:jar:3.3.9:compile
 |  +- org.codehaus.plexus:plexus-utils:jar:3.0.22:compile
 |  \- org.apache.commons:commons-lang3:jar:3.4:compile
 +- org.apache.maven.shared:maven-filtering:jar:3.1.1:compile
 |  +- org.codehaus.plexus:plexus-interpolation:jar:1.22:compile
 |  \- org.sonatype.plexus:plexus-build-api:jar:0.0.7:compile
 +- org.yaml:snakeyaml:jar:1.17:compile
 +- org.apache.commons:commons-compress:jar:1.14:compile
 +- org.apache.maven.shared:maven-invoker:jar:3.0.0:compile
 |  \- org.codehaus.plexus:plexus-component-annotations:jar:1.7:compile
 +- org.apache.maven:maven-core:jar:3.3.9:compile
 |  +- org.apache.maven:maven-model:jar:3.3.9:compile
 |  +- org.apache.maven:maven-settings:jar:3.3.9:compile
 |  +- org.apache.maven:maven-settings-builder:jar:3.3.9:compile
 |  |  \- org.apache.maven:maven-builder-support:jar:3.3.9:compile
 |  +- org.apache.maven:maven-repository-metadata:jar:3.3.9:compile
 |  +- org.apache.maven:maven-plugin-api:jar:3.3.9:provided
 |  +- org.apache.maven:maven-model-builder:jar:3.3.9:compile
 |  |  \- com.google.guava:guava:jar:18.0:compile
 |  +- org.apache.maven:maven-aether-provider:jar:3.3.9:compile
 |  |  \- org.eclipse.aether:aether-spi:jar:1.0.2.v20150114:compile
 |  +- org.eclipse.aether:aether-impl:jar:1.0.2.v20150114:compile
 |  +- org.eclipse.aether:aether-api:jar:1.0.2.v20150114:compile
 |  +- org.eclipse.aether:aether-util:jar:1.0.2.v20150114:compile
 |  +- com.google.inject:guice:jar:no_aop:4.0:compile
 |  |  +- javax.inject:javax.inject:jar:1:compile
 |  |  \- aopalliance:aopalliance:jar:1.0:compile
 |  +- org.codehaus.plexus:plexus-classworlds:jar:2.5.2:compile
 |  \- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile
 |     \- org.sonatype.plexus:plexus-cipher:jar:1.4:compile
 +- org.apache.maven:maven-plugin-descriptor:jar:2.2.1:compile
 +- org.apache.maven.reporting:maven-reporting-exec:jar:1.3:compile
 |  +- org.apache.maven.reporting:maven-reporting-api:jar:3.0:compile
 |  |  \- org.apache.maven.doxia:doxia-sink-api:jar:1.0:compile
 |  \- org.sonatype.aether:aether-util:jar:1.7:compile
 +- org.apache.maven.shared:maven-shared-utils:jar:3.1.0:compile
 +- org.codehaus.plexus:plexus-container-default:jar:1.7.1:compile
 |  +- org.apache.xbean:xbean-reflect:jar:3.7:compile
 |  \- com.google.collections:google-collections:jar:1.0:compile
 +- junit:junit:jar:4.12:compile
 |  \- org.hamcrest:hamcrest-core:jar:1.3:compile
 \- org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.3.3:compile
    +- javax.enterprise:cdi-api:jar:1.0:compile
    |  \- javax.annotation:jsr250-api:jar:1.0:compile
    \- org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.3.3:compile

关于我应该更改哪个依赖版本的任何建议?

1 个答案:

答案 0 :(得分:0)

我使用以下依赖项工作:

...
<properties>
    <maven.version>3.5.0</maven.version>
</properties>
...
<dependencies>
    ...
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-plugin-api</artifactId>
        <version>${maven.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-core</artifactId>
        <version>${maven.version}</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>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-aether-provider</artifactId>
        <version>3.3.9</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-compat</artifactId>
        <version>${maven.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-model</artifactId>
        <version>${maven.version}</version>
        <scope>test</scope>
    </dependency>
    ...
</dependencies>
...

基于Vincent Zurczak的博客文章:https://vzurczak.wordpress.com/2014/07/23/write-unit-tests-for-a-maven-plug-in/

当我将org.apache.maven:maven-core的范围设置为 test 时,就像在Zurczak的示例中一样,它打破了构建,因为我在org.apache.maven.project.MavenProject中使用了.gitignore我的魔力。