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

maven-jar-plugin classifier
maven-jar-plugin with-dependencies
jar will be empty - no content was marked for inclusion!
maven classifier
maven-jar-plugin manifest
maven jar plugin phases
maven jar plugin generate sources
maven-jar-plugin multiple executions

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.

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.

How to create an additional attached , How to create an additional attached jar artifact from the project or <excludes>/ <exclude> and add a classifier in your pom.xml. in a new execution, otherwise it will replace the default use of the jar-plugin instead of adding a second artifact. The classifier is also required to create more than one artifact. 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]

If your logs shows something like:

[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ test --
[WARNING] JAR will be empty - no content was marked for inclusion!

Adding a single useless class in src/main/java seems to solve the issue see:

http://maven.40175.n5.nabble.com/quot-mvn-clean-verify-deploy-quot-causes-jar-plugin-to-execute-twice-td5877166.html

Maven jar goal fails � Issue #1 � binkley/layers-kt � GitHub, java - Maven JAR Plugin 3.0.2 Error: You have to use a classifier to attach supplemental artifacts to the project instead of replacing them java. This avoids a bug in the M2E plugin which ships with Eclipse Neon, which issues the following warning: You have to use a classifier to attach artifacts to the project instead of replacing them.

In my case , I have setup the execution's ID as default-jar, then the error gone. e.g.

<execution>
    <id>default-jar</id>
    <phase>package</phase>
    <goals>
        <goal>jar</goal>
    </goals>
</execution>

Common problems with maven-jar-plugin 3.0.0 - java-devel, Circle CI is using jar plugin 3.0.2, in spite of pom asking for 2.6. matching the error in Circle CI: You have to use a classifier to attach supplementa to attach supplemental artifacts to the project instead of replacing them. 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]

subject:"maven\-jar\-plugin", Plugin fails with error message: "You have to use a classifier to attach supplemental artifacts to the project instead of replacing them. Maven JAR Plugin 3.0.2 Error: You have to use a classifier to attach supplemental artifacts to the project instead of replacing them with this approach. See also Maven `help:effective-pom` only generating for a single project, not all projects

maven-jar-plugin:3.1.3 failed to execute goal, [ANN] Apache Maven JAR Plugin Version 3.0.2 Released gmx.de> wrote: > > > Hi, > > > > using version 3.0.1 inside Eclipse, I now get the following error after > > updating my on project xxx: You have to use a classifier > to attach supplemental artifacts to the project instead of replacing > them. Whereas <jar.finalName>foo</jar.finalName> creates two jars: an executable jar including dependencies named foo-${project.version}.jar and a second jar only containing the project named ${project.name}-${project.version}.jar, <build><finalName>foo</finalName></build> creates only the executable jar including dependencies named foo.jar

imglib/imglib2, Another common use case for classifiers is to attach secondary artifacts to the project's main artifact. If you browse the Maven central repository, you will notice that the classifiers sources and javadoc are used to deploy the project source code and API docs along with the packaged class The quotation can be found here. Specify a list of fileset patterns to be included or excluded by adding <includes>/<include> or <excludes>/<exclude> and add a classifier in your pom.xml. Note: the jar-plugin must be defined in a new execution, otherwise it will replace the default use of the jar-plugin instead of adding a second artifact.

Comments
  • Thanks for the explanation - I faced the problem even though I've set packaging to "war" (and not "jar"), but removing the <phase>package</phase> inside the jar-plugin fixed the problem.
  • I get this error only in a multi module setup only in an environment using jenkins and linux. On a Mac OS machine things run and they also in the Travis CI environment. There seems to be more trickery going on which is frustrating. IMHO the error message is more confusing then helping and it only points to this stackoverflow article.
  • Thanks for the link! There is also mentioned the case of calling mvn clean verify deploy, which does everything until verify twice. In my case a mvn clean install deploy broke, but mvn clean deploy worked. (Had an empty JAR, too.)
  • That "works" but is based on the fact that having default-jar as the execution ID overrides the default execution from the jar packaging. This is a bit of a hack, and there is a better solution.