Eclipse Juno中的生命周期配置错误没有覆盖插件执行

时间:2021-02-05 23:13:42

Why does my Maven build work perfectly fine on the command line but when I run in Eclipse, it requires I add this section to my pom.xml, otherwise I get this error:

为什么我的Maven构建在命令行上工作得很好,但是当我在Eclipse中运行时,它需要我将这个部分添加到pom中。xml,否则会出现以下错误:

Plugin execution not covered by lifecycle configuration
: org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile
 (execution: default-testCompile, phase: test-compile)

Isn't it strange that this occurs around the 'maven-compiler-plugin' plugin?? I cannot find another question like this anywhere on google, although I find many fix suggestions around 3rd party plugins. I've done a great deal of researching and searching and found no explanation of this, not even from here.

这发生在“maven-编译-插件”插件中,这不是很奇怪吗?我在谷歌上找不到其他类似的问题,尽管我在第三方插件中找到了许多修复建议。我做了大量的研究和搜索,没有找到任何解释,甚至从这里也没有。

And the pom.xml required to fix this:

砰的一声。要解决这个问题,需要使用xml:

<!--This plugin's configuration is used to store Eclipse m2e 
settings only. It has no influence on the Maven build itself.-->
    <plugin>
        <groupId>org.eclipse.m2e</groupId>
        <artifactId>lifecycle-mapping</artifactId>
        <version>1.0.0</version>
        <configuration>
        <lifecycleMappingMetadata>
            <pluginExecutions>
                <pluginExecution>
                    <pluginExecutionFilter>
                    <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <versionRange>[3.1,)</versionRange>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </pluginExecutionFilter>
                    <action> 
                        <ignore></ignore>
                    </action>
                </pluginExecution>
            </pluginExecutions>
        </lifecycleMappingMetadata>
    </configuration>
</plugin>

And , here is my simple project on GitHub if you want to see my source.

这是我在GitHub上的简单项目,如果你想看我的源码。

3 个解决方案

#1


7  

I finally solved it. It appears that the "pluginManagement" section I posted above is required by an Eclipse Maven project in general, even though I resisted it, and even though no documentation that I can find on the internet ever mentions this explicitly.

我终于解决了它。我上面提到的“pluginManagement”部分似乎是Eclipse Maven项目所需要的,尽管我对此表示反对,而且即使我在internet上找不到任何文档明确地提到这一点。

ALso, the "versionRange" in the lifecycle exclusion section seems to also require the version number of the "gmaven-plugin" rather than the "version of Maven" which I was trying to give it above.

此外,生命周期排除部分中的“versionRange”似乎还需要“gmv -plugin”的版本号,而不是我在上面试图给出的“Maven版本”。

<pluginExecutionFilter>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <versionRange>[1.5,)</versionRange>
    <goals>
        <goal>testCompile</goal>
        <goal>compile</goal>
    </goals>
</pluginExecutionFilter>

#2


2  

You may require an M2E "connector" to understand maven-compiler-plugin using the Eclipse (JDT) compiler.

您可能需要一个M2E“连接器”来使用Eclipse (JDT)编译器来理解maven-compiler-plugin。

Select "discover connectors" and choose M2E connector for Eclipse JDT compiler provided by JBoss, or install it manually.

选择“发现连接器”,为JBoss提供的Eclipse JDT编译器选择M2E连接器,或者手动安装。

M2E connector for the Eclipse JDT Compiler 1.0.1.201209200903

用于Eclipse JDT编译器的M2E连接器1.0.1.1.201209200903

You may also be offered a Groovy connector -- maybe it uses similar technology under the hood? -- but unless you are using Groovy, it probably does not make sense to install such integration.

您可能还会得到一个Groovy连接器——也许它在引擎盖下使用了类似的技术?但是,除非使用Groovy,否则安装这样的集成可能没有意义。

#3


2  

  1. Help -> Install new Software

    帮助->安装新软件。

    • Install the Groovy Compiler 2.2 / 2.1 Feature

      安装Groovy编译器2.2 / 2.1特性

    • Install Groovy-Eclipse M2E integration

      安装Groovy-Eclipse M2E的集成

  2. Window -> Preferences -> Maven -> Lifecycle Mappings -> Open workspace lifecycle mappings metadata

    窗口->首选项-> Maven ->生命周期映射->开放工作区生命周期映射元数据

Add the following xml:

添加以下xml:

<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
    <pluginExecutions>
        <pluginExecution>
            <pluginExecutionFilter>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <versionRange>[1.3,)</versionRange>
                <goals>
                    <goal>compile</goal>
                    <goal>testCompile</goal>
                </goals>
            </pluginExecutionFilter>
            <action>
                <execute />
            </action>
        </pluginExecution>
    </pluginExecutions>
</lifecycleMappingMetadata>
  1. Reload the Lifecycle Mappings and invoke a projekt update on your maven project. (ALT+F5)
  2. 重新加载生命周期映射,并对maven项目调用projekt更新。(ALT + F5)

#1


7  

I finally solved it. It appears that the "pluginManagement" section I posted above is required by an Eclipse Maven project in general, even though I resisted it, and even though no documentation that I can find on the internet ever mentions this explicitly.

我终于解决了它。我上面提到的“pluginManagement”部分似乎是Eclipse Maven项目所需要的,尽管我对此表示反对,而且即使我在internet上找不到任何文档明确地提到这一点。

ALso, the "versionRange" in the lifecycle exclusion section seems to also require the version number of the "gmaven-plugin" rather than the "version of Maven" which I was trying to give it above.

此外,生命周期排除部分中的“versionRange”似乎还需要“gmv -plugin”的版本号,而不是我在上面试图给出的“Maven版本”。

<pluginExecutionFilter>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <versionRange>[1.5,)</versionRange>
    <goals>
        <goal>testCompile</goal>
        <goal>compile</goal>
    </goals>
</pluginExecutionFilter>

#2


2  

You may require an M2E "connector" to understand maven-compiler-plugin using the Eclipse (JDT) compiler.

您可能需要一个M2E“连接器”来使用Eclipse (JDT)编译器来理解maven-compiler-plugin。

Select "discover connectors" and choose M2E connector for Eclipse JDT compiler provided by JBoss, or install it manually.

选择“发现连接器”,为JBoss提供的Eclipse JDT编译器选择M2E连接器,或者手动安装。

M2E connector for the Eclipse JDT Compiler 1.0.1.201209200903

用于Eclipse JDT编译器的M2E连接器1.0.1.1.201209200903

You may also be offered a Groovy connector -- maybe it uses similar technology under the hood? -- but unless you are using Groovy, it probably does not make sense to install such integration.

您可能还会得到一个Groovy连接器——也许它在引擎盖下使用了类似的技术?但是,除非使用Groovy,否则安装这样的集成可能没有意义。

#3


2  

  1. Help -> Install new Software

    帮助->安装新软件。

    • Install the Groovy Compiler 2.2 / 2.1 Feature

      安装Groovy编译器2.2 / 2.1特性

    • Install Groovy-Eclipse M2E integration

      安装Groovy-Eclipse M2E的集成

  2. Window -> Preferences -> Maven -> Lifecycle Mappings -> Open workspace lifecycle mappings metadata

    窗口->首选项-> Maven ->生命周期映射->开放工作区生命周期映射元数据

Add the following xml:

添加以下xml:

<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
    <pluginExecutions>
        <pluginExecution>
            <pluginExecutionFilter>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <versionRange>[1.3,)</versionRange>
                <goals>
                    <goal>compile</goal>
                    <goal>testCompile</goal>
                </goals>
            </pluginExecutionFilter>
            <action>
                <execute />
            </action>
        </pluginExecution>
    </pluginExecutions>
</lifecycleMappingMetadata>
  1. Reload the Lifecycle Mappings and invoke a projekt update on your maven project. (ALT+F5)
  2. 重新加载生命周期映射,并对maven项目调用projekt更新。(ALT + F5)