如何映射Eclipse m2e插件未涵盖的Maven生命周期阶段?

时间:2022-01-12 21:30:27

I’m using Eclipse Kepler on Mac 10.9.5. I have imported a number of Maven projects using the m2e Eclipse plugin. All these projects are children of a parent pom. When I look at the “Overview” in the individual child pom.xml files, I see stuff like this:

我在Mac 10.9.5上使用Eclipse Kepler。我使用m2e Eclipse插件导入了许多Maven项目。所有这些项目都是父母的孩子。当我查看各个子pom.xml文件中的“概述”时,我看到如下内容:

Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2:write-project-properties (execution: default, phase: process-resources)

I would like Eclipse to execute these lifecycle phases at the appropriate times, but I’m not sure how to do that. When I select Eclipse’s suggestion …

我希望Eclipse在适当的时候执行这些生命周期阶段,但我不知道如何做到这一点。当我选择Eclipse的建议时......

Permanently mark goal write-project-properties in pom.xml as ignore

I selected the parent pom.xml file when prompted “Select location to place ignore,” however, the error does not go away when I view the child pom.xml file in the Eclipse editor. How can I map lifecycle phases not covered by m2e?

我在提示“选择要放置忽略的位置”时选择了父pom.xml文件,但是,当我在Eclipse编辑器中查看子pom.xml文件时,错误不会消失。如何映射m2e未涵盖的生命周期阶段?

Edit:

Per the answer, I went to Eclipse -> Preferences -> Maven -> Lifecycle Mappings, clicked on "Open Workspace Lifecycle Mappings Metadata", and edited the file as suggested ...

根据答案,我去了Eclipse - > Preferences - > Maven - > Lifecycle Mappings,点击了“Open Workspace Lifecycle Mappings Metadata”,并根据建议编辑了文件......

<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
    <pluginExecutions>
        <pluginExecution>
            <pluginExecutionFilter>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>xmlbeans-maven-plugin</artifactId>
                <versionRange>2.3.3</versionRange>
                <goals>
                    <goal>xmlbeans</goal>
                </goals>
            </pluginExecutionFilter>
            <action>
                <ignore />
            </action>
        </pluginExecution>
        <pluginExecution>
            <pluginExecutionFilter>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <versionRange>[1.0-alpha-2,)</versionRange>
                <goals>
                    <goal>write-project-properties</goal>
                </goals>
            </pluginExecutionFilter>
            <action>
                <execute />
            </action>
        </pluginExecution>
    </pluginExecutions>
</lifecycleMappingMetadata>

Even after restarting Eclipse, when I open a child pom.xml file, the "Plugin execution not covered by lifecycle configuration" errors remain as before.

即使在重新启动Eclipse之后,当我打开子pom.xml文件时,“生命周期配置未涵盖的插件执行”错误仍然像以前一样。

1 个解决方案

#1


M2Eclipse (the Maven integration plugin for Eclipse) is mapping and execution the default phases and goals of Maven into the internal Eclipse build workflow.

M2Eclipse(Eclipse的Maven集成插件)将Maven的默认阶段和目标映射和执行到内部Eclipse构建工作流程中。

See: https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html

[...] requires explicit instructions what to do with all Maven plugins bound to “interesting” phases [...] of a project build lifecycle. We call these instructions “project build lifecycle mapping” or simply “lifecycle mapping” because they define how m2e maps information from project pom.xml file to Eclipse workspace project configuration and behaviour during Eclipse workspace build.

[...]需要明确说明如何处理绑定到项目构建生命周期的“有趣”阶段的所有Maven插件。我们将这些指令称为“项目构建生命周期映射”或简称为“生命周期映射”,因为它们定义m2e如何将项目pom.xml文件中的信息映射到Eclipse工作区项目配置和Eclipse工作区构建期间的行为。

It is possible to solve this errors in every project or in your global Eclipse installation.

可以在每个项目或全局Eclipse安装中解决此错误。

Project build lifecycle mapping can be configured in a project’s pom.xml, contributed by Eclipse plugins, or defaulted to the commonly used Maven plugins shipped with m2e. We call these “lifecycle mapping metadata sources”.

项目构建生命周期映射可以在项目的pom.xml中配置,由Eclipse插件提供,或者默认为m2e附带的常用Maven插件。我们将这些称为“生命周期映射元数据源”。

The global Eclipse setting file is called lifecycle-mapping-metadata.xml and configurable via the 'Lifecycle Mappings' at the Maven Settings dialog[1].

全局Eclipse设置文件称为lifecycle-mapping-metadata.xml,可通过Maven Settings对话框中的'Lifecycle Mappings'进行配置[1]。

M2Eclipse matches plugin executions to actions using combination of plugin groupId, artifactId, version range and goal. There are three basic actions that M2Eclipse can be instructed to do with a plugin execution – ignore, execute and delegate to a project configurator.

M2Eclipse使用插件groupId,artifactId,版本范围和目标的组合将插件执行与动作相匹配。可以指示M2Eclipse执行插件执行的三个基本操作 - 忽略,执行和委托给项目配置器。

[...]

The ignore option, as the name suggests, tells M2Eclipse to silently ignore the plugin execution.

顾名思义,ignore选项告诉M2Eclipse默默地忽略插件执行。

[...]

The execute option tells m2e to execute the action as part of Eclipse workspace full or incremental build.

execute选项告诉m2e作为Eclipse工作区完整或增量构建的一部分执行操作。

delegate to a project configurator means there are adapter Eclipse plugins in the Eclipse Marketplace. A adapter plugin executes the phases and goals in a more Maven plugin specific way.

委托给项目配置器意味着Eclipse Marketplace中有适配器Eclipse插件。适配器插件以更多Maven插件特定的方式执行阶段和目标。

The real settings (the XML structure) isn't real intuitive but a bit described in the link above.

真实的设置(XML结构)并不是真正的直观,但在上面的链接中有点描述。

In your case the lifecycle-mapping-metadata.xml will be looks like:

在您的情况下,lifecycle-mapping-metadata.xml将如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
  <pluginExecutions>
[...]
    <pluginExecution>
      <pluginExecutionFilter>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <versionRange>[1.0-alpha-2,)</versionRange>
        <goals>
          <goal>write-project-properties</goal>
        </goals>
      </pluginExecutionFilter>
      <action>
        <ignore />
      </action>
    </pluginExecution>
[...]
  </pluginExecutions>
</lifecycleMappingMetadata>

ProTip: Did you have more projects and use a set of Maven plugins all the time, move the lifecycle-mapping-metadata.xml in SCM (git, svn, cvs ...).

ProTip:您是否有更多项目并且一直使用一组Maven插件,在SCM中移动lifecycle-mapping-metadata.xml(git,svn,cvs ...)。

EDIT

Add all goals of a plugin and maybe additional plugins to avoid these errors. Read the error message carefully for additional goals or plugins.

添加插件的所有目标以及可能的其他插件以避免这些错误。请仔细阅读错误消息以获取其他目标或插件。

After any saved change of lifecycle-mapping-metadata.xml you have to reload the content in the Maven Settings dialog[1] and update all Maven based projects in the workspace.

在任何已保存的lifecycle-mapping-metadata.xml更改之后,您必须在Maven设置对话框[1]中重新加载内容并更新工作区中所有基于Maven的项目。

Click the right mouse button on a Maven project in your Workspace and choose Maven > Update Projects .... Select the/all Maven Projects and activate the following checkboxes:

在工作区中的Maven项目上单击鼠标右键,然后选择Maven>更新项目....选择/ all Maven项目并激活以下复选框:

  • Update project configuration from pom.xml
  • 从pom.xml更新项目配置

  • Refresh workspace resources from local filesystem
  • 从本地文件系统刷新工作区资源

  • Clean projects

EDIT

[1] The Maven Settings dialog was located at File > Window > Preferences > Maven > Lifecycle Mappings until Exclipse Oxygen.

[1] Maven Settings对话框位于File> Window> Preferences> Maven> Lifecycle Mappings,直到Exclipse Oxygen。

#1


M2Eclipse (the Maven integration plugin for Eclipse) is mapping and execution the default phases and goals of Maven into the internal Eclipse build workflow.

M2Eclipse(Eclipse的Maven集成插件)将Maven的默认阶段和目标映射和执行到内部Eclipse构建工作流程中。

See: https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html

[...] requires explicit instructions what to do with all Maven plugins bound to “interesting” phases [...] of a project build lifecycle. We call these instructions “project build lifecycle mapping” or simply “lifecycle mapping” because they define how m2e maps information from project pom.xml file to Eclipse workspace project configuration and behaviour during Eclipse workspace build.

[...]需要明确说明如何处理绑定到项目构建生命周期的“有趣”阶段的所有Maven插件。我们将这些指令称为“项目构建生命周期映射”或简称为“生命周期映射”,因为它们定义m2e如何将项目pom.xml文件中的信息映射到Eclipse工作区项目配置和Eclipse工作区构建期间的行为。

It is possible to solve this errors in every project or in your global Eclipse installation.

可以在每个项目或全局Eclipse安装中解决此错误。

Project build lifecycle mapping can be configured in a project’s pom.xml, contributed by Eclipse plugins, or defaulted to the commonly used Maven plugins shipped with m2e. We call these “lifecycle mapping metadata sources”.

项目构建生命周期映射可以在项目的pom.xml中配置,由Eclipse插件提供,或者默认为m2e附带的常用Maven插件。我们将这些称为“生命周期映射元数据源”。

The global Eclipse setting file is called lifecycle-mapping-metadata.xml and configurable via the 'Lifecycle Mappings' at the Maven Settings dialog[1].

全局Eclipse设置文件称为lifecycle-mapping-metadata.xml,可通过Maven Settings对话框中的'Lifecycle Mappings'进行配置[1]。

M2Eclipse matches plugin executions to actions using combination of plugin groupId, artifactId, version range and goal. There are three basic actions that M2Eclipse can be instructed to do with a plugin execution – ignore, execute and delegate to a project configurator.

M2Eclipse使用插件groupId,artifactId,版本范围和目标的组合将插件执行与动作相匹配。可以指示M2Eclipse执行插件执行的三个基本操作 - 忽略,执行和委托给项目配置器。

[...]

The ignore option, as the name suggests, tells M2Eclipse to silently ignore the plugin execution.

顾名思义,ignore选项告诉M2Eclipse默默地忽略插件执行。

[...]

The execute option tells m2e to execute the action as part of Eclipse workspace full or incremental build.

execute选项告诉m2e作为Eclipse工作区完整或增量构建的一部分执行操作。

delegate to a project configurator means there are adapter Eclipse plugins in the Eclipse Marketplace. A adapter plugin executes the phases and goals in a more Maven plugin specific way.

委托给项目配置器意味着Eclipse Marketplace中有适配器Eclipse插件。适配器插件以更多Maven插件特定的方式执行阶段和目标。

The real settings (the XML structure) isn't real intuitive but a bit described in the link above.

真实的设置(XML结构)并不是真正的直观,但在上面的链接中有点描述。

In your case the lifecycle-mapping-metadata.xml will be looks like:

在您的情况下,lifecycle-mapping-metadata.xml将如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
  <pluginExecutions>
[...]
    <pluginExecution>
      <pluginExecutionFilter>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <versionRange>[1.0-alpha-2,)</versionRange>
        <goals>
          <goal>write-project-properties</goal>
        </goals>
      </pluginExecutionFilter>
      <action>
        <ignore />
      </action>
    </pluginExecution>
[...]
  </pluginExecutions>
</lifecycleMappingMetadata>

ProTip: Did you have more projects and use a set of Maven plugins all the time, move the lifecycle-mapping-metadata.xml in SCM (git, svn, cvs ...).

ProTip:您是否有更多项目并且一直使用一组Maven插件,在SCM中移动lifecycle-mapping-metadata.xml(git,svn,cvs ...)。

EDIT

Add all goals of a plugin and maybe additional plugins to avoid these errors. Read the error message carefully for additional goals or plugins.

添加插件的所有目标以及可能的其他插件以避免这些错误。请仔细阅读错误消息以获取其他目标或插件。

After any saved change of lifecycle-mapping-metadata.xml you have to reload the content in the Maven Settings dialog[1] and update all Maven based projects in the workspace.

在任何已保存的lifecycle-mapping-metadata.xml更改之后,您必须在Maven设置对话框[1]中重新加载内容并更新工作区中所有基于Maven的项目。

Click the right mouse button on a Maven project in your Workspace and choose Maven > Update Projects .... Select the/all Maven Projects and activate the following checkboxes:

在工作区中的Maven项目上单击鼠标右键,然后选择Maven>更新项目....选择/ all Maven项目并激活以下复选框:

  • Update project configuration from pom.xml
  • 从pom.xml更新项目配置

  • Refresh workspace resources from local filesystem
  • 从本地文件系统刷新工作区资源

  • Clean projects

EDIT

[1] The Maven Settings dialog was located at File > Window > Preferences > Maven > Lifecycle Mappings until Exclipse Oxygen.

[1] Maven Settings对话框位于File> Window> Preferences> Maven> Lifecycle Mappings,直到Exclipse Oxygen。