There are several ways to upload an artifact to nexus with or without using maven. This will be helpful when your code is not written in java or language that does not work well with maven. Or you just want to upload a file to nexus from command line as a part of build process. Whatever!
- Using Curl
Use Curl to directly upload a file to /content/repositories/<repo-id>/<path-of-file>.
curl -v -u nexusadmin:pwd –upload-file pom.xml http:// nexusrepo:8081/nexus/content/repositories/releases/com/sanjeev/demo/1.0/demo-1.0.pom
- Maven deploy plugin
You can use maven to deploy a file to nexus repo with the help of maven deploy plugin even if you are not using maven. The plugin has a two goals deploy and deploy-file. The deploy-file goal can be used to upload any file to a repo. This can be done as follows.
mvn deploy:deploy-file -DgroupId=com.sanjeev -DartifactId=demo -Dversion=1.0.0 -DgeneratePom=true -Dpackaging=jar -DrepositoryId=servernexus -Durl=http://nexuslocal:8081/nexus/content/repositories/releases -Dfile=target/demo-1.0.0.jar
If you have a pom.xml file you can use the following to upload the file.
mvn deploy:deploy-file -DgroupId=com.sanjeev -DartifactId=demo -Dversion=1.0.0 -DgeneratePom=false -Dpackaging=jar -DrepositoryId=servernexus -Durl=http://nexuslocal:8081/nexus/content/repositories/releases -DpomFile=pom.xml -Dfile=target/demo-1.0.0.jar
The servernexus is the server ID from your maven settings.xml file. This section tells which credential to use to upload the file to nexus. Please see Server Section of this maven settings documentation
- REST API Upload