Maven JAR插件3.0.2错误:您必须使用分类器将补充工件附加到项目而不是替换它们 [英] Maven JAR Plugin 3.0.2 Error: You have to use a classifier to attach supplemental artifacts to the project instead of replacing them

查看:3583
本文介绍了Maven JAR插件3.0.2错误:您必须使用分类器将补充工件附加到项目而不是替换它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Maven JAR插件(版本3.0.2)不断抛出以下错误,即使是单次调用 jar 目标

Maven JAR plugin (version 3.0.2) keeps throwing the following error, even for a single invocation of the jar goal:


[错误]无法执行目标org.apache.maven.plugins:maven-jar-plugin:3.0.2:jar(默认值)on项目测试:您必须使用分类器将补充工件附加到项目而不是替换它们。 - > [帮助1]

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:3.0.2:jar (default) on project test: You have to use a classifier to attach supplemental artifacts to the project instead of replacing them. -> [Help 1]

这是(最小?) pom.xml 这表明了问题:

Here's a (minimal?) pom.xml which demonstrates the problem:

<project xmlns="http://maven.apache.org/POM/4.0.0">
  <modelVersion>4.0.0</modelVersion>

  <groupId>test</groupId>
  <artifactId>test</artifactId>
  <version>1.0.0-SNAPSHOT</version>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.0.2</version>
        <executions>
          <execution>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

调用只是 mvn package


  • 根本不存在任何类/资源似乎无关紧要 - 无论如何都会出现上述错误消息。

  • 如果指定了两个目标,也会出现问题( jar test-jar )。

  • 如果指定无目标,则不会出现此问题。但这不是一个选项,因为我真的需要 jar test-jar

  • It doesn't seem to matter whether there are any classes/resources at all — the above error message appears anyway.
  • The problem also appears if two goals are specified (jar and test-jar).
  • The problem does NOT appear if no goals are specified. But this is not an option, since I really need both jar and test-jar.

根据文档分类器只需要在同一目标的多个调用中指定,并且有一个合理的默认为 test-jar 目标,我不打算更改。

According to the documentation, classifier only needs to be specified on multiple invocations of the same goal, and there's a reasonable default for the test-jar goal which I don't intend to change.

此外,问题似乎没有出现在JAR插件的2.x行上。

我错过了什么吗?
有人可以建议我做错了吗?

Did I miss something? Could anybody please suggest what I am doing wrong?

P.S。 Maven版本是3.3.9。

P.S. The Maven version is 3.3.9.

推荐答案

Jar插件实际上是通过配置执行两次:

The Jar Plugin is actually getting executed twice with the configuration:

<plugin>
  <artifactId>maven-jar-plugin</artifactId>
  <version>3.0.2</version>
  <executions>
    <execution>
      <goals>
        <goal>jar</goal>
      </goals>
    </execution>
  </executions>
</plugin>

如果您使用这样的配置检查日志,您将获得类似的内容:

If you check the logs with such a configuration, you will have something like:

[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ test ---
[INFO] Building jar: ...\test\target\test-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-jar-plugin:3.0.2:jar (default) @ test ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

意味着插件实际执行了两次。会发生什么,是Jar插件,在一个包装 jar 的项目中默认执行绑定到阶段。此默认执行是日志中提到的ID为 default-jar

meaning that the plugin was in fact executed twice. What happens, is that the Jar Plugin, in a project that has a packaging of jar has a default execution bound to the package phase. This default execution is the one mentioned in the logs with the ID of default-jar.

配置时插件中的< execution> ,您实际配置了一个新的执行,其中插件的 jar 目标是被调用。自 jar 目标默认绑定到阶段,执行在该阶段执行,在 jar固有的默认绑定之后执行包装。而且由于插件已经运行,它失败了,因为再次运行它实际上会替换第一次运行期间已经产生的主要工件。在 MJAR-198 中的插件3.0.0版中添加了此错误,因为发生这样的事情很可能是错误的配置,应尽早检测到。

When you configured an <execution> in the plugin, you actually configured a new execution, where the jar goal of the plugin is to be invoked. Since the jar goal binds by default to the package phase, that execution is getting executed at that phase, after the default binding inherent to the jar packaging. And since the plugin ran already, it is failing because running it again would actually replace the main artifact already produced during the first run. This error was added in version 3.0.0 of the plugin in MJAR-198, because such a thing happening is very likely a mis-configuration which should be detected early.

因此,修复很简单:没有执行指定目标 jar ,并让默认值(来自 jar 包装)完成工作。由于默认执行,即使没有 jar 目标的显式配置,JAR仍将被创建。如果您还想要测试JAR,请仍然需要配置插件来执行此操作

As such, the fix is simple: don't have an execution that specifies the goal jar, and let the default one (coming from the jar packaging) do the work. The JAR will still be created, even without the explicit configuration of the jar goal, thanks to the default execution. If you want a test JAR as well, you will still need to configure the plugin to do that with:

<plugin>
  <artifactId>maven-jar-plugin</artifactId>
  <version>3.0.2</version>
  <executions>
    <execution>
      <goals>
        <goal>test-jar</goal>
      </goals>
    </execution>
  </executions>
</plugin>

但请注意,目标 jar 不是指定。

But note that the goal jar is not specified.

这篇关于Maven JAR插件3.0.2错误:您必须使用分类器将补充工件附加到项目而不是替换它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆