1. 程式人生 > >maven的Plugin execution not covered by lifecycle configuration解決辦法

maven的Plugin execution not covered by lifecycle configuration解決辦法

錯誤型別:

Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-antrun-plugin:1.7:run (execution: define-classpath, phase: process-resources)

錯誤原因:

eclipse的m2e外掛還沒有支援到execution

網上找到的比較詳細的錯誤解釋:

To solve some long-standing issues, m2e 1.0 requires explicit instructions what to do with all Maven plugins bound to "interesting" phases (see 

M2E interesting lifecycle phases) of 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.

Project build lifecycle mapping configuration can be specified in project pom.xml, contributed by Eclipse plugins and there is also default configuration for some commonly used Maven plugins shipped with m2e. We call these "lifecycle mapping metadata sources". m2e will create error marker like below for all plugin executions that do not have lifecycle mapping in any of the mapping metadata sources.

Plugin execution not covered by lifecycle configuration:
org.apache.maven.plugins:maven-antrun-plugin:1.3:run(execution: generate-sources-input, phase: generate-sources)

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

解決方案:

修改pom檔案:

新增如下:

 <build>
  <pluginManagement>
    <plugins>
     <!-- add by M-->
        <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-antrun-plugin</artifactId>
                           <goals>
                          <goal>run</goal>
                      </goals>
                             <versionRange>[1.7,)</versionRange>
                        </pluginExecutionFilter>
                       <action>
                        <ignore />
                        </action>
                     </pluginExecution>
                 </pluginExecutions>
                </lifecycleMappingMetadata>
	   </configuration>  
       </plugin>  
       <!-- end ending -->        

注意在錯誤中,
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-antrun-plugin:1.7:run (execution: define-classpath, phase: process-resources)
上述所填內容中,groupId就是configuration冒號後面的內容,artifactId為再冒號後面的內容;版本號versionRange為後面的版本號,goal為版本號後面的run

如果該錯誤是出現在pom檔案中的parent標籤,則要在parent專案的pom檔案中新增該內容,如果是出現在本pom檔案的excution處,則是在該pom檔案出錯的plugins標籤內新增該內容。

最後要記得在修改完之後,點選專案的右鍵---Maven---Update Project

pluginManagement標籤的作用是作為公用的外掛配置項,給子專案共用的。

在eclipse->preference->maven->lifecycle mappings中,myeclipse的話Maven4MyEclipse->Lifecycle mappings,想上面所示進行配置,儲存更新project。eclipse預設配置路徑是沒有lifecycle-mapping-metadata.xml這個檔案的,只有<專案名>.lifecyclemapping一系列這樣的檔案,但提供一個按鈕“Open workspace lifecycle mappings metadata”裡進行編輯。或者Change mapping file location。       好吧,這樣也許是最應該的處理的方式,但讓每個開發人員都改下ide配置,還不如直接改下pom.xml檔案的配置,最終採用了修改pom.xml檔案的方式。 基於maven的專案,使用各種maven plugin來完成開發中的各種工作,例如編譯程式碼,打包,部署等等… 每個plugin包含許多的goal,用來做特定的事情。典型的基於java的maven專案就有 clean compile test package deploy等goal要執行。除了這些比較常見的goal之外,專案中還可以使用大量的第三方的plugin,甚至自己動手開發的plugin。 隨之而來的問題是,在eclipse中編輯maven專案的時候,eclipse並不知道這些goal要做什麼,通用的goal還好說,特殊用途的goal就沒有辦法了。所以m2eclipse這個整合maven到eclipse的plugin就提供了開發extra的能力,eclipse利用這些extra來完成本來在maven plugin要乾的活。 如果eclipse沒有辦法知道某個goal要幹什麼,那麼通常就會看到如下的錯誤資訊: Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-dependency-plugin:2.6:copy (execution: default, phase: validate) 由於我個人更傾向於在命令列下讓maven幹活,而eclipse更多的只是充當編輯器的角色,所以我要的只是讓eclipse忽略掉這些goal就好了。

參考: