m2eclipse报错:Plugin execution not covered by lifecy

简介:

   今天在导入以前写的maven项目时,遇到了一个问题,下面是pom.xml中的代码片段:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
< plugin >
   < groupId >com.google.code.maven-replacer-plugin</ groupId >
   < artifactId >replacer</ artifactId >
   < version >1.5.2</ version >
   < executions >
     <!-- Replace path token in mybatisGeneratorConfig.xml -->
     < execution >
       < id >Replace the path token in mybatisGeneratorConfig.xml</ id >
       < phase >initialize</ phase >
       < goals >
         < goal >replace</ goal >
       </ goals >
       < configuration >
         < file >${project.basedir}/src/main/resources/mybatisGeneratorConfig.xml</ file >
         < replacements >
           < replacement >
             < token >solution.basedir</ token >
             < value >${solution.basedir}</ value >
           </ replacement >
         </ replacements >
       </ configuration >
     </ execution >
   < executions >
< plugin >

在<execution>节点上老是报错:Plugin execution not covered by lifecycle configuration,如图

193533_IhIY_1434710.png

为什么会出现上面的结果呢?就是因为我是在Eclipse中使用的maven,即m2eclipse。这里有eclipse官网的描述:https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html

图中也给出了两种方式来解决,但这种直接在该Module中Ignore这个错误是不合适的,而且对于一个开发来说,不知道为什么要这样做也是不能满足的。于是经过一番搜索和折腾,发现使用<pluginManagement>元素将<plugins>标签包裹一下,也可以解决该问题(请参见:http://stackoverflow.com/questions/10483180/maven-what-is-pluginmanagement):

?
1
2
3
4
5
6
7
8
9
< build >
   < pluginManagement >
     < plugins >
       < plugin > ... </ plugin >
       < plugin > ... </ plugin >
           ....
     </ plugins >
   </ pluginManagement >
</ build >

那么,<pluginManagement>元素有什么作用呢?怀着好奇心,我接着去折腾,以下是答案:

From Maven documentation:

    pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children. The children have every right to override pluginManagement definitions.

它和<plugin>元素有什么区别呢?

  • <pluginManagement/> defines the settings for plugins that will be inherited by multiple modules in your build. This is great for cases where you have a parent pom file.

  • <plugins/> is an actual invocation of the plugin. It may or may not be inherited from a <pluginManagement/>.

需要注意的是:

You don't need to have a <pluginManagement/> in your project, if it's not a parent POM. However, if it's a parent pom, then in the child's pom, you need to have a declaration like:

?
1
2
3
4
5
6
< plugins >
     < plugin >
         < groupId >com.foo</ groupId >
         < artifactId >bar-plugin</ artifactId >
     </ plugin >
</ plugins >

Notice how you aren't defining any configuration. You can inherit it from the parent, unless you need to further adjust your invocation as per the child project's needs.

正好我出错的pom是一个child module,于是我就在parent中定义了以下内容:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  < pluginManagement >
   < plugins >
     <!--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 >
           
             <!-- 在Parent Module的pom.xml中忽略 -->   
             < pluginExecution >
               < pluginExecutionFilter >
                 < groupId >com.google.code.maven-replacer-plugin</ groupId >
                 < artifactId >replacer</ artifactId >
                 <!-- 这个范围是指,版本大于1.5的都忽略 -->
                 < versionRange >[1.5,)</ versionRange >
                 < goals >
                   <!-- 这里的goal就是在原来child module中plugin定义的goal -->
                   < goal >replace</ goal >
                 </ goals >
               </ pluginExecutionFilter >
               < action >
                 <!-- 记住这个ignore元素 -->
                 < ignore />
               </ action >
             </ pluginExecution >
             
           </ pluginExecutions >
         </ lifecycleMappingMetadata >
       </ configuration >
     </ plugin >
   </ plugins >
</ pluginManagement >

以下是在Parent Module中处理之后的截图:

200943_J8wn_1434710.png

以同样的方式,我们就可以在Parent Module中同时管理多个plugin的execution过程了。如果其他的maven plugin也报Plugin execution not covered by lifecycle configuration的错将这些execution的信息都加入到Parent Module的<pluginManagement>元素中即可。

Stackoverflow上也有人使用以下方式,经本人测试可行,于是写在这里:

1. 在Eclipse的Workspace下找到以下文件(没有就创建):Workspace/.metadata/.plugins/org.eclipse.m2e.core/lifecycle-mapping-metadata.xml并打开;

2. 在<pluginExecutions>节点下粘贴刚刚在Parent Module中添加的内容,若没有该文件,创建一个,使得修改后的完整内容为:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<? xml  version = "1.0"  encoding = "UTF-8" ?>
< lifecycleMappingMetadata >
   < pluginExecutions >
   
     < pluginExecution >
       < pluginExecutionFilter >
         < groupId >com.google.code.maven-replacer-plugin</ groupId >
         < artifactId >replacer</ artifactId >
         < versionRange >[1.5,)</ versionRange >
         < goals >
           < goal >replace</ goal >
         </ goals >
       </ pluginExecutionFilter >
       < action >
         < ignore />
       </ action >
     </ pluginExecution >
     
   </ pluginExecutions >
</ lifecycleMappingMetadata >

当然,以后其他plugin execution需要ignore的,也可以在这里声明。

3.  修改文件之后,记得在Eclipse中:Windows -> Preferences -> Maven -> Lifecycle mappings点击Reload workspace lifecycle mappings metadata使之生效即可。如图:

211128_8hBy_1434710.jpg211313_lAho_1434710.jpg

4. 如果还没生效,在project上 右键 -> Maven -> Update Project... 将更新应用到project中。


对于这两种方式,我个人觉得还是第一种更好使,因为第一种方式不依赖于Eclipse环境,在pom.xml中配置好后,可以在任何的eclipse中导入均不会有错


目录
相关文章
|
6月前
|
Java Android开发
Eclipse里面导工程的时候报错faceted project problem
Eclipse里面导工程的时候报错faceted project problem
|
应用服务中间件 Android开发
Eclipse报错,unable to install breakpoint in ...
Eclipse报错,unable to install breakpoint in ...
822 0
|
Java Android开发
eclipse 导入项目源码报错(最全问题及解决方案)
我们在使用 eclipse 导入源码时,经常会出现一些意想不到的问题,出现各种报错或者是乱码,这里我汇总了eclipse导入项目出现问题的方法及解决方案,希望能帮助到大家
644 0
eclipse 导入项目源码报错(最全问题及解决方案)
|
Java Maven Android开发
eclipse 中 maven的pom.xml文件发生错误:CoreException: Could not get the value for parameter compilerId for plugin execution default-compile: PluginResolutionException: Plugin org.apache.maven...
eclipse 中 maven的pom.xml文件发生错误:CoreException: Could not get the value for parameter compilerId for plugin execution default-compile: PluginResolutionException: Plugin org.apache.maven...
527 0
eclipse 中 maven的pom.xml文件发生错误:CoreException: Could not get the value for parameter compilerId for plugin execution default-compile: PluginResolutionException: Plugin org.apache.maven...
|
5月前
|
Android开发
eclipse报错问题解决
eclipse报错问题解决
|
6月前
|
Java Android开发
eclipse项目报错的解决方案
eclipse项目报错的解决方案
46 0
|
9月前
|
Java Android开发 Windows
成功解决eclipse启动报错 Error:Could not create the Java Virtual Machine Error:A fatal exception has occurred
成功解决eclipse启动报错 Error:Could not create the Java Virtual Machine Error:A fatal exception has occurred
|
IDE Java 程序员
Eclipse 安装插件报错:An error occurred while collecting items to be installed session context was...解决方法汇总
Eclipse 安装插件报错:An error occurred while collecting items to be installed session context was...解决方法汇总
742 0
Eclipse 安装插件报错:An error occurred while collecting items to be installed session context was...解决方法汇总
|
IDE 编译器 程序员
Eclipse 的常见报错、警告和原因分析、解决方式以及相关操作快捷键小结(持续更新)
Eclipse 的常见报错、警告和原因分析、解决方式以及相关操作快捷键小结(持续更新)
469 0
Eclipse 的常见报错、警告和原因分析、解决方式以及相关操作快捷键小结(持续更新)
|
Java Linux Android开发
eclipse的jar包在Linux中报错
eclipse的jar包在Linux中报错
eclipse的jar包在Linux中报错