How can I map Maven lifecycle phases not covered by the Eclipse m2e plugin?

随声附和 提交于 2019-11-30 18:33:57

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

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.

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

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”.

The global Eclipse setting file is called lifecycle-mapping-metadata.xml and configurable via the 'Lifecycle Mappings' at the Maven Settings dialog[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.

[...]

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

[...]

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

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.

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

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

<?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 ...).

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.

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:

  • Update project configuration from 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!