yeg*_*256 26 java maven-plugin maven-3
我正在尝试使用maven-plugin-testing-harness以下测试用例的2.1版:
public class FooTest extends AbstractMojoTestCase {
  @Override
  protected void setUp() throws Exception {
    super.setUp();
  }
  public void testSomething() throws Exception {
    // todo
  }
}
测试失败了setUp():
org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException
  role: org.apache.maven.repository.RepositorySystem
roleHint: 
    at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:257)
    at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:245)
    at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:239)
    at org.codehaus.plexus.PlexusTestCase.lookup(PlexusTestCase.java:206)
    at org.apache.maven.plugin.testing.AbstractMojoTestCase.setUp(AbstractMojoTestCase.java:118)
    at foo.FooTest.setUp(FooTest.java:54)
这些依赖关系我在pom.xml:
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-plugin-api</artifactId>
        <version>3.0.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-model</artifactId>
        <version>3.0.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-core</artifactId>
        <version>3.0.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugin-testing</groupId>
        <artifactId>maven-plugin-testing-harness</artifactId>
        <version>2.1</version>
        <scope>test</scope>
    </dependency>
有任何想法吗?
小智 49
最近我遇到了同样的例外.经过一番研究后,我发现maven-compat插件解决了这个问题:
<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-compat</artifactId>
    <version>3.0.5</version>
    <scope>test</scope>
</dependency>
将此留给今后遇到此问题的任何人:
smoke的答案确实有效,但要确保原始问题中yegor256中包含的依赖项版本匹配.添加org.apache.maven:maven-compat对我来说不起作用,直到我将这4个依赖项更改为3.0.5版本.
| 归档时间: | 
 | 
| 查看次数: | 10973 次 | 
| 最近记录: |