使用Maven插件测试中的org.apache.maven.repository.RepositorySystem进行组件查找exception

我正在尝试使用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中的这些依赖项:

   org.apache.maven maven-plugin-api 3.0.5   org.apache.maven maven-model 3.0.5   org.apache.maven maven-core 3.0.5   org.apache.maven.plugin-testing maven-plugin-testing-harness 2.1 test  

有任何想法吗?

最近我遇到了同样的例外。 经过一番研究后,我发现maven-compat插件解决了这个问题:

  org.apache.maven maven-compat 3.0.5 test  

将此留给今后遇到此问题的任何人:

smoke的答案确实有效,但要确保原始问题中yegor256中包含的依赖项版本匹配。 添加org.apache.maven:maven-compat对我来说不起作用,直到我将这4个依赖项更改为3.0.5版本。