Maven deploy + source classifiers
Asked Answered
M

3

5

I'm trying to deploy a Maven artifact with a classifier. Since I need both the sources and the JAR (I'm using it from GWT), I would like to get artifact-version-classifier.jar and artifact-version-classifier-sources.jar. However, it works fine with the compiled JAR, but fails with the sources (the output sources JAR has a wrong name).

This is the configuration that I have so far:

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <classifier>prod</classifier>
    </configuration>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <executions>
        <execution>
            <id>attach-sources</id>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <finalName>${project.build.finalName}-prod</finalName>
    </configuration>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <configuration>
        <classifier>prod</classifier>
    </configuration>
</plugin>

And this is the output I'm getting for mvn deploy:

Uploading: http://juicebox:8080/archiva/repository/snapshots//ar/com/nubing/afip-connector/1.0-SNAPSHOT/afip-connector-1.0-SNAPSHOT-prod.jar
237K uploaded  (afip-connector-1.0-SNAPSHOT-prod.jar)

But this one has a wrong name:

Uploading: http://juicebox:8080/archiva/repository/snapshots//ar/com/nubing/afip-connector/1.0-SNAPSHOT/afip-connector-1.0-SNAPSHOT-sources.jar
228K uploaded  (afip-connector-1.0-SNAPSHOT-sources.jar)
Marlo answered 14/12, 2011 at 3:46 Comment(0)
U
10

Sadly, attaching a source JAR with an arbitrary classifier is not supported by the source plugin. When the source artifact is attached, the classifier is hardcoded (as of version 2.1.2 of source plugin).

You can work around the issue by getting the source plugin to generate the JAR but not attach, and attach it with the build helper plugin's attach artifact goal.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>attach-source-jar</id>
            <phase>package</phase>
            <goals>
                <goal>attach-artifact</goal>
            </goals>
            <configuration>
                <artifacts>
                    <artifact>
                        <file>${project.build.directory}/${project.build.finalName}-prod-sources.jar</file>
                        <type>jar</type>
                        <classifier>prod-sources</classifier>
                    </artifact>
                </artifacts>
            </configuration>
        </execution>
    </executions>
</plugin>
Uteutensil answered 14/12, 2011 at 4:32 Comment(1)
@Uteutensil this is fixed in version 2.2Tacmahack
T
4

Used the same workaround as prunge for this. But that's no longer necessary. This is a reported Bug that was fixed in version 2.2 in June 2012: Just set the property <classifier>. Tested with 2.2.1 .

Tacmahack answered 12/7, 2013 at 7:43 Comment(0)
F
1

A bit more of an updated answer, using sources and javadoc

<maven.javadoc.version>3.0.1</maven.javadoc.version>
<maven.source.version>3.0.1</maven.source.version>


<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>${maven.source.version}</version>
    <configuration>
        <classifier>jre10-sources</classifier>
    </configuration>
</plugin>



 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>${maven.javadoc.version}</version>
    <configuration>
        <classifier>jre10-javadoc</classifier>
    </configuration>
</plugin>
Forequarter answered 14/8, 2018 at 21:2 Comment(1)
Thisi is the only correct solution which should be accepted as a SOLUTION.Dactylology

© 2022 - 2024 — McMap. All rights reserved.