断言失败错误:需要 Maven 3.2.4 或更高版本(运行版本 3.2.5)



在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的依赖项?为什么它没有检测到正确的版本?

任何帮助/建议将非常有帮助。

附言此错误在我添加一个特定的 mojo 后开始发生。如果我删除 Mojo,它构建得很好。魔术中可能是什么原因造成的?


编辑:

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

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:

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

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

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

我使用以下依赖项让它工作:

...
<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范围时,就像 Zurczak 的示例一样,它破坏了构建,因为我在我的 mojo 中使用了org.apache.maven.project.MavenProject

相关内容

最新更新