java - org.codehaus.plexus.component.repository.exception.ComponentLookupException : java. util.NoSuchElementException

标签 java maven maven-3 maven-plugin

我尝试测试我的 Maven 插件并收到奇怪的异常。发现类似问题 here ,但答案没有帮助。

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>

测试类:

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();
    }
}

测试项目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>

异常(exception):

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

最佳答案

我在一个具有适当目标的正确执行配置的模块中遇到了这个问题。我通过简单地在该特定模块中运行 mvn clean install 解决了这个问题(没有从本地存储库中删除任何内容)。

关于java - org.codehaus.plexus.component.repository.exception.ComponentLookupException : java. util.NoSuchElementException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34529565/

相关文章:

eclipse - Sublime Text 2 编辑的文件更改在 Maven 项目中刷新浏览器时不显示

java - selenium headless chrome java忽略ssl错误

java - REST URL 通常是如何定义的?

java - 使用 Jsoup 选择没有类的 HTML 元素

maven - izpack-maven-plugin 默认情况下不包含 native 库

java - 无法启动 OSGi 包,缺少 com.ibm.uvm.tools

java - 带有嵌入式表单的 Camunda Spring Boot 启动器

java - maven-nar-plugin 和依赖模块中的测试

maven - 如何列出项目中定义的所有 Maven 配置文件,包括所有子模块?

maven - 从 pom 中的项目版本中删除 -SNAPSHOT