Deploy SNAPSHOT artifact and sources to Nexus from Maven command line

b0ss picture b0ss · Jan 6, 2012 · Viewed 10.1k times · Source

I am trying to deploy one EXE file and it's zipped source file to Sonatype Nexus using maven command line. Files must be deployed as SNAPSHOTs.

So, I have 2 files:

-testXYZ.exe and source file
-testXYZ.zip

Using maven 2.2.1 and command described here:

mvn deploy:deploy-file -Durl=file:///home/me/m2-repo \
                       -DrepositoryId=some.repo.id \
                       -Dfile=./path/to/artifact-name-1.0.jar \
                       -DpomFile=./path/to/pom.xml \
                       -Dsources=./path/to/artifact-name-1.0-sources.jar \
                       -Djavadoc=./path/to/artifact-name-1.0-javadoc.jar

I can deploy EXE, but cannot deploy source, because maven 2.2.1 is using deploy-plugin v2.5 and this command is not supported until v2.7. It is not allowed to me to use newer versions of maven, so I try different approach.

Using these two subsequent commands I can deploy these two artifacts, but, source cannot be downloaded from nexus.

call mvn deploy:deploy-file -DgroupId=com.xyz -DartifactId=testXYZ -Dversion=1.1.116-SNAPSHOT -Dpackaging=zip -Dfile=testXYZ.zip -Dclassifier=sources -Durl=http://build:8081/nexus/content/repositories/snapshots -DrepositoryId=nexus
call mvn deploy:deploy-file -DgroupId=com.xyz -DartifactId=testXYZ -Dversion=1.1.116-SNAPSHOT -Dpackaging=exe -Dfile=testXYZ.exe -Durl=http://build:8081/nexus/content/repositories/snapshots -DrepositoryId=nexus

After deploy, i search for testXYZ and click on artifact source download link. Nexus says:

"Item not found on path "com.xyz:testXYZ:1.1.116-SNAPSHOT:c=sources:e=jar"!"

Problem is the way maven upload these artifacts:

Line form log file while source is uploading:
Uploaded: http://build:8081/nexus/content/repositories/snapshots/com/xyz/testXYZ/1.1.116-SNAPSHOT/testXYZ-1.1.116-20120106.111705-1-sources.zip
Line form log file while Main artifact is uploading:
Uploaded: http://build:8081/nexus/content/repositories/snapshots/com/xyz/testXYZ/1.1.116-SNAPSHOT/testXYZ-1.1.116-20120106.111709-2.exe

Notice 111705-1 and 111705-2. Last number must be the same if we wish Nexus can generate correct links.

This approach is described here:

Deploying an artifact, its sources and javadoc using maven's deploy:deploy-file plugin

and here:

http://maven.apache.org/plugins/maven-install-plugin/examples/installing-secondary-artifacts.html

and it working for fixed versions(for example 1.1.116), but not for SNAPSHOTs.

Exe and Zip files can be deployed to Nexus (like jar files), if fixed version is used.

So, question is: Is there a way to deploy artifact and source SNAPSHOTs from command line to Sonatype Nexus and to be sure that these files can be downloaded by clicking on sources and artifacts links?

Note: If I disable timestamps suffix, this can work, but I do not want to do this.

-DuniqueVersion=false

Thanks,

Marjan

Answer

b0ss picture b0ss · Jan 10, 2012

I found partial solution for this problem. I can call specific version of maven-deploy-plugin like this:

mvn org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file...

This way, artifacts and sources SNAPSHOTs can be deployed to Nexus avoiding any problems with download, but it behave like

-DuniqueVersion=false

is still there.