Maven JAR Plugin 3.0.2 Error: You have to use a classifier to attach supplemental artifacts to the project instead of replacing them

Alex Shesterov :

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

[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]

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>

The invocation is just mvn package.

  • 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.

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.

Also, the problem doesn't seem to appear on the 2.x line of the JAR plugin.

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

P.S. The Maven version is 3.3.9.

Tunaki :

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] ------------------------------------------------------------------------

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.

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.

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>

But note that the goal jar is not specified.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Pull all artifacts from Maven Artifactory instead of just JAR artifacts

While building the project getting error , Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.10.4:jar (attach-javadocs)

Use deployed artifacts instead of local project in sbt multi project build

Using maven 3, how to use project classpath in a plugin?

"You don't have a SNAPSHOT project in the reactor projects list." when using Jenkins Maven release plugin

Which artifacts should I use for JAXB RI in my Maven project?

Maven 3 - Distribute custom plugin in a .jar?

Why Executable jar created using maven-assembly-plugin for a multi-module maven project showing classnotfound error

Maven error: "You don't have a SNAPSHOT project in the reactor projects list."

What could possibly be wrong in creating maven project if you have error in pom.xml file

How to use a jar file as a library in a maven project

maven project not recognizing some artifacts

Eclipse maven plugin only download JAR package instead of AAR package

TensorFlow binary classifier outputs predictions for 3 classes instead of 2?

Maven (eclipse) use shaded jar instead of original jar

Docusign API attach supplemental documents

Attach source to jar library in Maven

Difference between Jar and Plugin in Java and when to use them

Eclipse - How to add a project as a Maven dependency to another, instead of adding as a jar?

Unofficial migrate Nexus 2 -> 3 possible for Maven artifacts?

Open API code generator Maven plugin uses old Swagger 2 annotations instead of Swagger 3 annotations

How would you add key values instead of replacing them. Python Dictionary

How to use a maven project jar in a normal java project

code ship fails with error - You have to be inside an angular-cli project in order to use the serve command

How to use Maven assembly plugin with multi module maven project

Execution attach-javadocs of goal org.apache.maven.plugins:maven-javadoc-plugin:3.0.0:jar failed with Java10

How do I open a Java project (that uses maven) in Eclipse? (Do I use M2E or maven-eclipse-plugin)

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin (default-compile) on project: Fatal error compiling: tools.jar not found

Error Number: 1064 You have an error in your SQL syntax; right syntax to use near '3 = ''' at line 1