2015-12-30 13 views
6

Próbuję przetestować moją wtyczkę maven i otrzymać dziwny wyjątek. Znaleziono podobne pytanie here, ale odpowiedź nie pomogła.org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException

pom.xml

<dependencies> 
    <dependency> 
     <groupId>org.apache.maven</groupId> 
     <artifactId>maven-plugin-api</artifactId> 
     <version>3.3.9</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.maven</groupId> 
     <artifactId>maven-project</artifactId> 
     <version>3.0-alpha-2</version> 
    </dependency> 
    <dependency> 
     <groupId>com.jcabi</groupId> 
     <artifactId>jcabi-aether</artifactId> 
     <version>0.10.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.maven.plugin-tools</groupId> 
     <artifactId>maven-plugin-annotations</artifactId> 
     <version>3.4</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.maven.plugin-testing</groupId> 
     <artifactId>maven-plugin-testing-harness</artifactId> 
     <version>3.3.0</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.maven</groupId> 
     <artifactId>maven-aether-provider</artifactId> 
     <version>3.3.9</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.maven</groupId> 
     <artifactId>maven-core</artifactId> 
     <version>3.3.9</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.maven</groupId> 
     <artifactId>maven-compat</artifactId> 
     <version>3.3.9</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.maven</groupId> 
     <artifactId>maven-model</artifactId> 
     <version>3.3.9</version> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.12</version> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

klasa Test: projekt

public class ConverterMojoTest { 

    @Rule 
    public MojoRule rule = new MojoRule() { 

     @Override 
     protected void before() throws Throwable { 
      super.before(); 
     } 

     @Override 
     protected void after() { 
      super.after(); 
     } 
    }; 

    @Rule 
    public TestResources resources = new TestResources(); 


    @Test 
    public void testExecute() throws Exception { 
     File project = resources.getBasedir("valid"); 
     File pom = new File(project, "pom.xml"); 
     Assert.assertNotNull(pom); 
     Assert.assertTrue(pom.exists()); 

     ConverterMojo mojo = (ConverterMojo) rule.lookupMojo("convert", pom); 
     Assert.assertNotNull(mojo); 
     mojo.execute(); 
    } 
} 

test pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.my.utils.test</groupId> 
    <artifactId>project-to-test</artifactId> 
    <version>1.0.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 
    <name>Test</name> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>com.my.utils</groupId> 
       <artifactId>converter-maven-plugin</artifactId> 
       <configuration> 

       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

Wyjątek:

org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException 
     role: org.apache.maven.plugin.Mojo 
    roleHint: com.my.utils:converter-maven-plugin:1.0.0-SNAPSHOT:convert 
+0

Wyślij także swój kod mojo. Najprawdopodobniej twój cel nie jest zdefiniowany jako "konwersja". – carlspring

+0

Czy moja odpowiedź nie działa ...? – carlspring

+0

Czy znalazłeś rozwiązanie? Mam ten sam problem i nie mam pomysłów ... Mój test POM zawiera sekcję ''. – lazlev

Odpowiedz

1

Twojego projektu testowego pom.xml musi mieć sekcję <execution/> z odpowiednim <goal/>:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
          http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.my.utils.test</groupId> 
    <artifactId>project-to-test</artifactId> 
    <version>1.0.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>Test</name> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>com.my.utils</groupId> 
       <artifactId>converter-maven-plugin</artifactId> 

       <configuration> 
        ... 
       </configuration> 

       <executions> 
        <execution> 
         <goals> 
          <goal>convert</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

Inaczej, uprząż badania nie powiedzie się zrozumieć, co to ma do map i obciążenia.

+0

To nie działa. Ten sam wyjątek został odrzucony. Podwójnie sprawdź, czy moja wartość celu jest zgodna. – MMP

0

Miałem ten sam problem, poszedłem za radą, ale wciąż miałem problem. Rozwiązałem go, usuwając lokalne repo, a następnie wykonując instalację mvn clean -DskipTests z terminala. Następnie uruchomiłem mój test jUnit od Eclipse i działało. Musiała gdzieś być sprzeczna zależność.

Powiązane problemy