Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven deploy + source classifiers

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)
like image 594
ninja.user Avatar asked Dec 12 '22 07:12

ninja.user


2 Answers

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>
like image 77
prunge Avatar answered Jan 01 '23 16:01

prunge


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 .

like image 27
Marc von Renteln Avatar answered Jan 01 '23 18:01

Marc von Renteln