如何在pom.xml中修复m2e错误:生命周期配置未涵盖插件执行?

时间:2015-11-17 16:02:08

标签: java eclipse maven m2e

我在Maven Java项目中提到了标题错误。下面是一个好项目和我的问题项目的比较。 enter image description here

  • 如何解决这两个错误?
  • 在上层好的中,为什么有这么多configurator, configurator,...?即使没有错误标记,它看起来也很奇怪。

我已阅读帖子:How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds

但它没有提供干净的镜头。它充满了解释,但没有规范的解决方案。

顺便说一下,我对Maven XML mess 感到非常沮丧,我必须找到一些替代方案。

ADD 1 - 问题部分修复,但不确定根本原因,以及那么多configurator s。

好的,我注意到在日食的Installation Details中,没有m2e个项目。奇怪的是如何在不安装的情况下导入maven项目。无论如何,我从http://www.eclipse.org/m2e/安装最新的1.6.2。而上述问题已经消失。 但这只是一个解决方案。我仍然不知道为什么会有这么多configurator ......

ADD 2 - 添加我的pom.xml,它不是有效的pom。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.its</groupId>
    <artifactId>cloud</artifactId>
    <name>MyCloud</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <properties>
        <java-version>1.7</java-version>
        <org.springframework-version>4.2.2.RELEASE</org.springframework-version> 
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
        <org.apache.logging.log4j-version>2.4.1</org.apache.logging.log4j-version>
    </properties>
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                 </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>

        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj-version}</version>
        </dependency>   

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>

        <!-- @Inject -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-websocket</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.2.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.2.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>${org.apache.logging.log4j-version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>org.test.int1.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

2 个答案:

答案 0 :(得分:3)

M2Eclipse需要明确说明如何处理绑定到项目构建生命周期某些阶段的所有Maven插件。这些指令被称为“生命周期映射”,因为它们定义了m2e如何将项目pom.xml文件中的信息映射到Eclipse配置。可以指示M2Eclipse执行插件执行的一个操作是委托给项目配置器。

引用this reference page

  

配置程序映射告诉M2Eclipse使用projectConfigurators扩展点将用于匹配插件执行的工作空间项目配置映射委托给使用m2e注册的AbstractProjectConfigurator的实现。

这些扩展点位于每个Eclipse插件中。如果你看一下${ECLIPSE_HOME}\plugins,你会发现一些名字以org.eclipse.m2e开头的罐子。这些是M2Eclipse插件。

让我们以maven-war-plugin的一些配置程序为例。要查看声明配置程序的位置,可以解压缩org.eclipse.m2e.wtp_1.2.1.20150819-2220.jar(根据您的M2Eclipse版本名称可能不同)并打开文件lifecycle-mapping-metadata.xml。对于war包装,这就是我所拥有的:

<lifecycleMapping>
  <packagingType>war</packagingType>
  <lifecycleMappingId>org.maven.ide.eclipse.wtp.WarLifecycleMapping</lifecycleMappingId>
  <pluginExecutions>
    <pluginExecution>
      <pluginExecutionFilter>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <versionRange>[2.0.1,)</versionRange>
        <goals>
          <goal>war</goal>
        </goals>
      </pluginExecutionFilter>
      <action>
        <configurator>
          <id>org.maven.ide.eclipse.configuration.wtp.configurator</id>
        </configurator>
      </action>
    </pluginExecution>
    <pluginExecution>
      <pluginExecutionFilter>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <versionRange>[2.0.1,)</versionRange>
        <goals>
          <goal>war</goal>
        </goals>
      </pluginExecutionFilter>
      <action>
        <configurator>
          <id>org.maven.ide.eclipse.configuration.wtp.warmanifest.configurator</id>
        </configurator>
      </action>
    </pluginExecution>           
    <pluginExecution>
      <pluginExecutionFilter>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <versionRange>[0.0.1,2.0.1)</versionRange>
        <goals>
          <goal>war</goal>
        </goals>
      </pluginExecutionFilter>
      <action>
        <error>
            <message>maven-war-plugin prior to 2.0.1 is not supported by m2e-wtp. Use maven-war-plugin version 2.0.1 or later</message>
        </error>
      </action>
    </pluginExecution>           
    <pluginExecution>
      <pluginExecutionFilter>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <versionRange>[2.0.1,)</versionRange>
        <goals>
          <goal>war</goal>
        </goals>
      </pluginExecutionFilter>
      <action>
        <configurator>
          <id>org.maven.ide.eclipse.configuration.wtp.overlay.configurator</id>
        </configurator>
      </action>
    </pluginExecution>       
    <pluginExecution>
      <pluginExecutionFilter>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <versionRange>[1.0,)</versionRange>
        <goals>
          <goal>inplace</goal>
          <goal>exploded</goal>
          <goal>manifest</goal>
        </goals>
      </pluginExecutionFilter>
      <action>
        <ignore>
            <message>maven-war-plugin goals "inplace", "exploded", "manifest" are ignored by m2e</message>
        </ignore>
      </action>
    </pluginExecution>
  </pluginExecutions>
</lifecycleMapping>

你可以看到这声明了配置器。所有这些配置程序都是您在帖子中的对话框图片中看到的配置文件。

根据您的Eclipse安装,可以声明maven-war-plugin的其他配置程序:

  • 对于JSF,它们在org.eclipse.m2e.wtp.jsf_1.2.1.20150819-2220.jar
  • 中声明
  • 对于JAX-RS,它们在org.eclipse.m2e.wtp.jaxrs_1.2.1.20150819-2220.jar
  • 中声明

M2Eclipse extension development页面记录了如何创建新的m2e扩展程序,并以antlr3-maven-plugin为例。

答案 1 :(得分:-1)

你可以使用插件 基本上没有正确的配置这种类型的错误产生..
           org.eclipse.m2e      生命周期映射      1.0.0                                                                  一些组ID                一些伪影ID                [1.0.0,)                                  一些目标的