33

I'm trying to use maven-plugin-testing-harness version 2.1 with the following test case:

public class FooTest extends AbstractMojoTestCase {
  @Override
  protected void setUp() throws Exception {
    super.setUp();
  }
  public void testSomething() throws Exception {
    // todo
  }
}

The test fails at the setUp() call:

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)

These dependencies I have in the 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>

Any ideas?

yegor256
  • 102,010
  • 123
  • 446
  • 597
  • I'm also having this problem. I don't suppose you found a solution did you? – ksclarke Apr 27 '13 at 22:25
  • 1
    Possible duplicate: http://stackoverflow.com/questions/14939341/error-injecting-defaultrepositorysystem-in-maven-plugin-testing-harness. I'm having this problem as well. – Noremac May 01 '13 at 20:14
  • I'm on maven 3.8.6, and none of the suggested solutions worked for me. – Holly Cummins Sep 21 '22 at 18:05

3 Answers3

62

Recently I faced the same exception. After a bit researching I found that maven-compat plugin solves the problem:

<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-compat</artifactId>
    <version>3.0.5</version>
    <scope>test</scope>
</dependency>
smoke
  • 619
  • 4
  • 8
7

Leaving this here for anyone who runs into this problem in the future:

smoke's answer does work, but make sure the versions of the dependencies included in yegor256's in the original question match. Adding org.apache.maven:maven-compat did not work for me until I had changed those 4 dependencies to also have version 3.0.5.

Rob
  • 100
  • 1
  • 3
  • Change version of maven is also solution when you get this error "java.langRuntimeException: org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException, role: org.apache.maven.execution.MavenExecutionRequestPopulator" while you try to update maven repositories in IDEA settings (Settings -> Build, Execution, Deployment -> Build Tools -> Maven -> Repositories). – Krzysiek Aug 12 '15 at 11:55
1

Currently, the class org.apache.maven.repository.RepositorySystem is found in the lib maven-resolver-api. If after adding maven-compat, anybody here still gets the error, make sure to add maven-resolver-api artifact as dependency as well.

<dependency>
  <groupId>org.apache.maven.resolver</groupId>
  <artifactId>maven-resolver-api</artifactId>
  <version>1.3.1</version>
</dependency>
Ismael Sarmento
  • 844
  • 1
  • 11
  • 22