1、在eclipse中,点击window-->Preferences中,找到Maven-->LifecycleMappings选项,如下图所示
这个lifecycle-mapping-metadata.xml文件在相关的目录中是不存在的,这是工作区的配置,如果在项目pom.xml中如果不做声明的话,在使用maven插件时会报各种错误。如果你的eclipse还没有m2e的话,去help-->Eclipse Marketplace中,查找m2e,然后安装就可以了。我看网上有资料讲,安装后在eclipse的安装目录下plugin目录下,有以下这种包,我在我的eclipse的安装目录下没看到,
org.eclipse.m2e.lifecyclemapping.defaults_xxxxxx.jar
因为我的eclipse正好安装在c盘,我就在c盘根目录下,查找所有*m2e*.jar包,然后找到一个包名叫:
org.eclipse.m2e.jdt_2.3.500.20240602-2342.jar
这里面有名叫lifecycle-mapping-metadata.xml的文件 解压出来,以此为基础修改或增加,加入自己想要的maven 未识别的插件:如下面:代码段
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<versionRange>[3.4,)</versionRange>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
</action>
同时也加入其也需要版本的maven plugin。别忘记在上面图片中的change mapping file location指定到你刚刚修改的lifecycle-mapping-metadata.xml(不晓得这个文件在其他什么地方可以找到)。去试一下吧,对你有用,请点赞再走。根据网上的帖子,把我的修改后的lifecycle-mapping-metadata.xml的完整文件贴出来,有需要的可以拷贝一份:
<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
<lifecycleMappings>
<lifecycleMapping>
<packagingType>war</packagingType>
<lifecycleMappingId>org.eclipse.m2e.jdt.JarLifecycleMapping</lifecycleMappingId>
</lifecycleMapping>
</lifecycleMappings>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<goals>
<goal>resources</goal>
<goal>testResources</goal>
<goal>copy-resources</goal>
</goals>
<versionRange>[2.4,)</versionRange>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<goals>
<goal>resources</goal>
<goal>testResources</goal>
<goal>copy-resources</goal>
</goals>
<versionRange>[0.0.1,2.4)</versionRange>
</pluginExecutionFilter>
<action>
<error>
<message>maven-resources-plugin prior to 2.4 is not supported by m2e Use maven-resources-plugin version 2.4 or later.</message>
</error>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<goals>
<goal>enforcer</goal>
</goals>
<versionRange>[1.0-alpha-1,)</versionRange>
</pluginExecutionFilter>
<action>
<ignore>
<message>maven-enforcer-plugin (goal "enforece") is ignored by m2e.</message>
</ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<goals>
<goal>install</goal>
</goals>
<versionRange>[1.6-SONATYPE-r940877,)</versionRange>
</pluginExecutionFilter>
<action>
<ignore>
<message>maven-invoker-plugin (goal "install") is ignored by m2e.</message>
</ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>process</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore>
<message>maven-remote-resources-plugin (goal "process") is ignored by m2e.</message>
</ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<versionRange>[0,)</versionRange>
<goals>
<goal>configure-workspace</goal>
<goal>eclipse</goal>
<goal>clean</goal>
<goal>to-maven</goal>
<goal>install-plugins</goal>
<goal>make-artifacts</goal>
<goal>myeclipse</goal>
<goal>myeclipse-clean</goal>
<goal>rad</goal>
<goal>rad-clean</goal>
</goals>
</pluginExecutionFilter>
<action>
<error>
<message>maven-eclipse-plugin is not compatible with m2e.</message>
</error>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<versionRange>[2.0,)</versionRange>
<goals>
<goal>jar-no-fork</goal>
<goal>test-jar-no-fork</goal>
<!--theoretically, the following goals should not by bound to lifecycle, but ignore them just in case.-->
<goal>jar</goal>
<goal>aggregate</goal>
<goal>test-jar</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<versionRange>[1.0-beta-1,)</versionRange>
<goals>
<goal>create</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<versionRange>[1.8.2,)</versionRange>
<goals>
<goal>idl-protocol</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<versionRange>[1.8.2,)</versionRange>
<goals>
<goal>protocol</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<versionRange>[1.8.2,)</versionRange>
<goals>
<goal>schema</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<versionRange>[2.17,)</versionRange>
<goals>
<goal>check</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<versionRange>[3.8,)</versionRange>
<goals>
<goal>check</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<goals>
<goal>resources</goal>
<goal>testResources</goal>
<goal>copy-resources</goal>
</goals>
<versionRange>[2.4,)</versionRange>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<goals>
<goal>resources</goal>
<goal>testResources</goal>
<goal>copy-resources</goal>
<goal>test</goal>
</goals>
<versionRange>[2.4,)</versionRange>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>