Maven插件的测试与Maven 3.0.4不兼容。

5

我有一个针对Maven插件的简单测试:

public class SimpleMavenTest extends AbstractMojoTestCase {

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        // code
    }

    public void testCase() throws Exception {
        // test case
    }

    @Override
    protected void tearDown() throws Exception {
        // code
        super.tearDown();
    }
}

使用这种maven-surefire-plugin配置:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <forkMode>never</forkMode>
      </configuration>
    </plugin>
  </plugins>
</build>

在 maven 3.0.4 发布之前,我的 SimpleMavenTest 成功运行。但是当我使用 maven 3.0.4 运行测试时,出现了下一个错误:

java.lang.IllegalStateException: The internal default plexus-bootstrap.xml is missing. This is highly irregular, your plexus JAR is most likely corrupt.
    at org.codehaus.plexus.DefaultPlexusContainer.initializeConfiguration(DefaultPlexusContainer.java:1052)
    at org.codehaus.plexus.DefaultPlexusContainer.initialize(DefaultPlexusContainer.java:627)
    at org.codehaus.plexus.PlexusTestCase.setUp(PlexusTestCase.java:119)
    at org.apache.maven.plugin.testing.AbstractMojoTestCase.setUp(AbstractMojoTestCase.java:69)
    at org.maven.test.MyMojoTest.setUp(MyMojoTest.java:12)
    at junit.framework.TestCase.runBare(TestCase.java:128)
    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:120)
    at junit.framework.TestSuite.runTest(TestSuite.java:230)
    at junit.framework.TestSuite.run(TestSuite.java:225)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

我查看了这里:http://maven.apache.org/plugins/maven-surefire-plugin/examples/class-loading.html 并尝试以以下方式更改 maven-surefire-plugin 的配置:

<configuration>
        <forkMode>once</forkMode>
</configuration>

一切都正常。但如果我进行以下操作:

<forkMode>never</forkMode>

出现了上述错误。这很奇怪,因为在 Maven 3.0.3 及以前的版本中,测试都可以正常运行而没有任何错误。有什么想法吗?


1
我有类似的设置,但是我的surefire配置中有版本信息,格式如下:<version>${surefire.version}</version>。不确定是否有帮助,你可以试试吗? - Venki
你的pom文件中有这个groupId的条目吗?<groupId>org.apache.maven.wagon</groupId> - Venki
我尝试添加<version>${surefire.version}</version>,但错误再次发生了。 我有这个条目:<groupId>org.apache.maven.plugins</groupId>。我用你的尝试替换它:<groupId>org.apache.maven.wagon</groupId>,测试运行成功。谢谢你的帮助! 但我需要它与<groupId>org.apache.maven.plugins</groupId>一起工作,并且如我上面所写,很有趣:为什么它在maven 3.0.3上运行而在maven 3.0.4上不起作用。 - rdiachenko
上周我遇到了这个问题,虽然觉得很不寻常。我会尝试暴力破解并查看结果。如果你想的话,我可以将其列为此帖子的答案。 - Venki
如果您找到了解决方案,请在此处发布。我也会继续在这个问题上进行搜索。 - rdiachenko
1个回答

1

我在jira.codehaus.org上开了一个bug,得到的答复是这个问题已经在maven-surefire-plugin v.2.11中解决了。由于我使用的是2.10版本,所以出现了错误。最新的surefire插件版本是2.12,因此请按照以下方式更改surefire配置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12</version>
    <configuration>
        <forkMode>never</forkMode>
    </configuration>
</plugin>

并且测试将会成功运行。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接