eclipse m2e 不支持 maven-dependency-plugin(目标“copy-dependencies”、“unpack”)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8706017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:48:24  来源:igfitidea点击:

maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supported by m2e

eclipsemavenm2eclipse

提问by Naftuli Kay

I have a fairly simple Maven project:

我有一个相当简单的 Maven 项目:

<project>
    <dependencies>
        ...
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/dependencies</outputDirectory>
                        </configuration>    
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

However, I get the following error in m2eclipse:

但是,我在 m2eclipse 中收到以下错误:

Description Resource    Path    Location    Type
maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supported by m2e. pom.xml  /jasperreports-test line 60 Maven Project Build Lifecycle Mapping Problem

Why do I care if m2eclipse doesn't "support" this task? Maven does, and that's all I really care about. How can I get this error in my project to go away?

为什么我关心 m2eclipse 不“支持”这个任务?Maven 做到了,这就是我真正关心的。我怎样才能让我的项目中的这个错误消失?

回答by maksimov

It seems to be a known issue. You can instruct m2e to ignore this.

这似乎是一个已知问题。您可以指示 m2e 忽略这一点。

Option 1: pom.xml

选项 1:pom.xml

Add the following inside your <build/>tag:

<build/>标签中添加以下内容:

<pluginManagement>
<plugins>
    <!-- Ignore/Execute plugin execution -->
    <plugin>
        <groupId>org.eclipse.m2e</groupId>
        <artifactId>lifecycle-mapping</artifactId>
        <version>1.0.0</version>
        <configuration>
            <lifecycleMappingMetadata>
                <pluginExecutions>
                    <!-- copy-dependency plugin -->
                    <pluginExecution>
                        <pluginExecutionFilter>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-dependency-plugin</artifactId>
                            <versionRange>[1.0.0,)</versionRange>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                        </pluginExecutionFilter>
                        <action>
                            <ignore />
                        </action>
                    </pluginExecution>
                </pluginExecutions>
            </lifecycleMappingMetadata>
        </configuration>
    </plugin>
   </plugins></pluginManagement>

You will need to do Maven... -> Update Project Configuration on your project after this.

在此之后,您将需要对您的项目执行 Maven... -> 更新项目配置。

Read more: http://wiki.eclipse.org/M2E_plugin_execution_not_covered#m2e_maven_plugin_coverage_status

阅读更多:http: //wiki.eclipse.org/M2E_plugin_execution_not_covered#m2e_maven_plugin_coverage_status

Option 2: Global Eclipse Override

选项 2:全局 Eclipse 覆盖

To avoid changing your POM files, the ignore override can be applied to the whole workspace via Eclipse settings.

为避免更改 POM 文件,可以通过 Eclipse 设置将忽略覆盖应用于整个工作区。

Save this file somewhere on the disk: https://gist.github.com/maksimov/8906462

将此文件保存在磁盘上的某个位置:https: //gist.github.com/maksimov/8906462

In Eclipse/Preferences/Maven/Lifecycle Mappingsbrowse to this file and click OK:

Eclipse/Preferences/Maven/Lifecycle Mappings浏览到此文件并单击确定:

Eclipse Settings

日食设置

回答by Caio Cunha

This is a problem of M2E for Eclipse M2E plugin execution not covered.

这是 Eclipse M2E 插件执行的 M2E 问题未涵盖

To solve this problem, all you got to do is to map the lifecycle it doesn't recognize and instruct M2E to execute it.

要解决这个问题,您要做的就是映射它无法识别的生命周期并指示 M2E 执行它。

You should add this after your plugins, inside the build. This will remove the error and make M2E recognize the goal copy-depenciesof maven-dependency-pluginand make the POM work as expected, copying dependencies to folder every time Eclipse build it. If you just want to ignore the error, then you change <execute />for <ignore />. No need for enclosing your maven-dependency-plugininto pluginManagement, as suggested before.

你应该在你的plugins, 在build. 这将删除错误,使M2E识别目标copy-depenciesmaven-dependency-plugin,使POM工作不如预期,复制依赖于它的文件夹,每次Eclipse构建。如果你只是想忽略错误,那么你就改变<execute /><ignore />。无需封闭的maven-dependency-plugin进入pluginManagement,因为之前提出。

<pluginManagement>
  <plugins>
    <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-dependency-plugin</artifactId>
                <versionRange>[2.0,)</versionRange>
                <goals>
                  <goal>copy-dependencies</goal>
                </goals>
              </pluginExecutionFilter>
              <action>
                <execute />
              </action>
            </pluginExecution>
          </pluginExecutions>
        </lifecycleMappingMetadata>
      </configuration>
    </plugin>
  </plugins>
</pluginManagement>

回答by user311174

If copy-dependencies, unpack, pack, etc., are important for your project you shouldn't ignore it. You have to enclose your <plugins>in <pluginManagement>tested with Eclipse Indigo SR1, maven 2.2.1

如果复制依赖项、解包、打包等对您的项目很重要,则不应忽略它。您必须附上经过 Eclipse Indigo SR1、maven 2.2.1 测试的<plugins>in<pluginManagement>

回答by mario

To make it work, instead of ignoring it, you can install the m2e connector for the maven-dependency-plugin:
https://github.com/ianbrandt/m2e-maven-dependency-plugin

要使其工作,而不是忽略它,您可以为 maven-dependency-plugin 安装 m2e 连接器:https:
//github.com/ianbrandt/m2e-maven-dependency-plugin

Here is how you would do it in Eclipse:

以下是您在 Eclipse 中的操作方法:

  1. go to Window/Preferences/Maven/Discovery/
  2. enter Catalog URL: http://download.eclipse.org/technology/m2e/discovery/directory-1.4.xml
  3. click Open Catalog
  4. choose the m2e-maven-dependency-plugin
  5. enjoy
  1. 转到窗口/首选项/Maven/发现/
  2. 输入目录 URL:http: //download.eclipse.org/technology/m2e/discovery/directory-1.4.xml
  3. 点击打开目录
  4. 选择 m2e-maven-dependency-plugin
  5. 请享用

回答by SGB

Despite answer from CaioToOn above, I still had problems getting this to work initially.

尽管上面的 CaioToOn 给出了答案,但我仍然无法在最初使用它时遇到问题。

After multiple attempts, finally got it working. Am pasting my final version here - hoping it will benefit somebody else.

经过多次尝试,终于成功了。我在这里粘贴我的最终版本 - 希望它会对其他人有益。

    <build> 
        <plugins>
            <!--
            Copy all Maven Dependencies (-MD) into libMD/ folder to use in classpath via shellscript
             --> 
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/libMD</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <!--  
        Above maven-dependepcy-plugin gives a validation error in m2e. 
        To fix that, add the plugin management step below. Per: http://stackoverflow.com/a/12109018
        -->
        <pluginManagement>
            <plugins>
                <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-dependency-plugin</artifactId>
                                        <versionRange>[2.0,)</versionRange>
                                        <goals>
                                            <goal>copy-dependencies</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

回答by Myluco

I had the same problem when trying to load Hadoop project in eclipse. I tried the solutions above, and I believe it might have worked in Eclipse Kepler... not even sure anymore (tried too many things).

尝试在 Eclipse 中加载 Hadoop 项目时遇到了同样的问题。我尝试了上面的解决方案,我相信它可能在 Eclipse Kepler 中有效......甚至不确定(尝试了太多东西)。

With all the problems I was having, I decided to move on to Eclipse Luna, and the solutions above did not work for me.

考虑到我遇到的所有问题,我决定继续使用 Eclipse Luna,但上述解决方案对我不起作用。

There was another post that recommended changing the ... tag to package. I started doing that, and it would "clear" the errors... However, I start to think that the changes would bite me later - I am not an expert on Maven.

还有另一篇文章建议将 ... 标签更改为 package。我开始这样做,它会“清除”错误......但是,我开始认为这些变化会在以后咬我 - 我不是 Maven 专家。

Fortunately, I found out how to remove all the errors. Go to Window->Preferences->Maven-> Error/Warnings and change "Plugin execution not covered by lifecycle..." option to "Ignore". Hope it helps.

幸运的是,我发现了如何删除所有错误。转到窗口->首选项->Maven->错误/警告并将“生命周期未涵盖的插件执行...”选项更改为“忽略”。希望能帮助到你。

回答by blue-sky

Another option is to navigate to problems tab, right click on error, click apply quick fix. The should generate the ignore xml code and apply it .pom file for you.

另一种选择是导航到问题选项卡,右键单击错误,单击应用快速修复。应该生成忽略 xml 代码并将其应用到 .pom 文件中。

回答by Andna

I know this is old post but I struggled today with this problem also and I used template from this page: http://maven.apache.org/plugins/maven-dependency-plugin/usage.html

我知道这是旧帖子,但我今天也遇到了这个问题,我使用了这个页面中的模板:http: //maven.apache.org/plugins/maven-dependency-plugin/usage.html

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>[ groupId ]</groupId>
                  <artifactId>[ artifactId ]</artifactId>
                  <version>[ version ]</version>
                  <type>[ packaging ]</type>
                  <classifier> [classifier - optional] </classifier>
                  <overWrite>[ true or false ]</overWrite>
                  <outputDirectory>[ output directory ]</outputDirectory>
                  <destFileName>[ filename ]</destFileName>
                </artifactItem>
              </artifactItems>
              <!-- other configurations here -->
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

and everything works fine under m2e1.3.1.

并且在m2e1.3.1下一切正常。

When I tried to use

当我尝试使用

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/dependencies</outputDirectory>
                    </configuration>    
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I also got m2eerror.

我也有m2e错误。