【问题标题】:Tests for maven plugins are incompatible with maven 3.0.4maven 插件的测试与 maven 3.0.4 不兼容
【发布时间】:2012-03-03 04:57:27
【问题描述】:

我有一个简单的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 和以前的 maven 版本上,测试运行时没有任何错误。有什么想法吗?

【问题讨论】:

  • 我有类似的设置,但我的surefire配置中有版本信息,如下所示 ${surefire.version} 。不确定它是否有帮助。你可以试试吗?
  • 你的 pom 中有这个组 id 的条目吗? org.apache.maven.wagon
  • 我尝试添加${surefire.version},但又出现错误。我有这个条目:org.apache.maven.plugins。我用您的尝试替换它: org.apache.maven.wagon 并成功试运行。谢谢你的帮助!但我需要它与 org.apache.maven.plugins 一起使用,正如我在上面所写的,这很有趣:为什么它适用于 maven 3.0.3 而不适用于 maven 3.0.4。跨度>
  • 我上周遇到了这个问题,但发现它很不寻常。我会尝试暴力破解它,看看会发生什么。如果你愿意,我可以把它列为这篇文章的答案。
  • 如果您找到解决方案,请在此处发布。我也会在这个麻烦中继续搜索。

标签: java unit-testing maven maven-plugin


【解决方案1】:

我在 jira.codehaus.org 上打开了a 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>

测试将成功运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    相关资源
    最近更新 更多