Maven generating two jar files when used with "classifier" tag

build, java, maven

Solution

Looking at the documentation it seems that classifier is used to generate additional jars.

See here:

Specify a list of fileset patterns to be included or excluded by adding / or / 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. The classifier is also required to create more than one artifact.

So, as per document it sounds as if you do not provide `<id>` to execution it will overwrite the default jar mechanism and give you a single jar with `-gc.jar` appendix. But it does not. You always end up with two jars.

I have hacked it a bit, you can just override the default settings by using default plug-in id. So, here is what gives me single jar with `-gc.jar` name.

<build>
  <plugins>
    ...
    <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
            <execution>
                <id>default-jar</id>
                <phase>package</phase>
                <goals>
                    <goal>jar</goal>
                </goals>
                <configuration>
                    <classifier>gc</classifier>
                </configuration>
            </execution>
        </executions>
    </plugin>
  </plugins>  
</build>

Problem

My project requires me to take open source code, tune it and use it as a dependency. When I build it, I want to append a classifier with it (so as to distinguish between modified and original code). Following is snippet form pom.xml. ``` <plugins> <plugin> <artifactId>maven-jar-plugin</artifactId> <executions> <execution> <id>gc-custom</id> <goals> <goal>jar</goal> </goals> <configuration> <classifier>gc</classifier> </configuration> </execution> </executions> </plugin> </plugins> ``` My issue is that after I fire build, maven is generating both jar files (with and without classifier attached) i.e. output contains 2 jar files named "atlassian-pageobjects-api-2.1-m14.jar", "atlassian-pageobjects-api-2.1-m14-gc.jar". I am using following command to build: mvn clean install Please help and let me know what is wrong here.

Original source