How can I programmatically upload an artifact into Nexus 3?

There are several ways to upload artifacts into Nexus 3 without running a build. (See this article for Nexus 2)

Direct Deploy

You can do an HTTP PUT of a file into /repository/<repo-id>/<path-of-file>.  Using curl you can do this with:

curl -v -u admin:admin123 --upload-file pom.xml http://localhost:8081/repository/maven-releases/org/foo/1.0/foo-1.0.pom

Maven "deploy-file" Deployment

You can deploy files using the "deploy-file" goal on the Maven deploy plugin

Example without a pom file:

mvn deploy:deploy-file -DgroupId=com.somecompany -DartifactId=project -Dversion=1.0.0 -DgeneratePom=true -Dpackaging=jar -DrepositoryId=nexus -Durl=http://localhost:8081/repository/maven-releases -Dfile=target/project-1.0.0.jar

With a pom file:

mvn deploy:deploy-file -DgroupId=com.somecompany -DartifactId=project -Dversion=1.0.0 -DgeneratePom=false -Dpackaging=jar -DrepositoryId=nexus -Durl=http://localhost:8081/repository/maven-releases -DpomFile=pom.xml -Dfile=target/project-1.0.0.jar

This plugin goal also allows deployment of snapshot versions, and the plugin will take care of calculating the timestamped version needed:

mvn deploy:deploy-file -DgroupId=com.somecompany -DartifactId=project -Dversion=1.0.0-SNAPSHOT -DgeneratePom=true -Dpackaging=jar -DrepositoryId=nexus -Durl=http://localhost:8081/repository/maven-snapshots -Dfile=target/project-1.0.0-SNAPSHOT.jar

Note: The "repositoryId" parameter is not a Nexus repository ID, it is the ID of a server section in your settings.xml file which has then credentials needed for deployment. If these credentials are not configured you will see an error like: "Return code is: 401, ReasonPhrase: Unauthorized."

<servers>
...
  <server>
      <id>nexus</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>
  </servers>

Maven "wagon" Deployment

You can deploy files using the "upload-single" goal on the Maven Wagon plugin. This approach is useful when deploying adhoc files to a "raw" repository.

mvn wagon:upload-single -Dwagon.url=http://localhost:8081/repository/rawhosted/ -Dwagon.serverId=nexus -Dwagon.fromFile=fileToUpload.txt

Note: The "wagon.serverId" parameter is not a Nexus repository ID, it is the ID of a server section in your settings.xml file which has then credentials needed for deployment. See the note above for an example.

Have more questions? Submit a request

0 Comments

Article is closed for comments.
Powered by Zendesk