<TABLE OF CONTENTS>
There are several ways to upload artifacts into Nexus Repo 2 without running a build. (See this article for Nexus Repo 3)
You can do an HTTP PUT of a file into /content/repositories/<repo-id>/<path-of-file>. Using curl you can do this with:
curl -v -u admin:admin123 --upload-file pom.xml http://localhost:8081/nexus/content/repositories/releases/org/foo/1.0/foo-1.0.pom
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/nexus/content/repositories/releases -Dfile=target/project-1.0.0.jar
With a pom file:
mvn deploy:deploy-file -DgeneratePom=false -DrepositoryId=nexus -Durl=http://localhost:8081/nexus/content/repositories/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/nexus/content/repositories/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.
Alternatively you can use the REST API. This requires a multi-part form POST to /service/local/artifact/maven/content.
Here are some examples using curl.
curl -v -F r=releases -F hasPom=false -F e=jar -F g=com.test -F a=project -F v=1.0 -F p=jar -F firstname.lastname@example.org -u admin:admin123 http://localhost:8081/nexus/service/local/artifact/maven/content
curl -v -F r=releases -F hasPom=true -F e=jar -F email@example.com -F firstname.lastname@example.org -u admin:admin123 http://localhost:8081/nexus/service/local/artifact/maven/content
curl -v -F r=releases -F hasPom=true -F email@example.com -u admin:admin123 http://localhost:8081/nexus/service/local/artifact/maven/content
Important: The file parameters MUST COME LAST or the curl commands will not work. If you are uploading a pom file, then the pom file parameter must come before the rest of the file parameters, but after all the other parameters.
For reference, here are all the available form parameters for this endpoint:
r : repository
hasPom - whether you are supplying the pom or you want one generated. If you are uploading a pom, then the parameters g, a, v, p, and c are not needed as part of the command as those values are extracted from the pom.ml
e - extension
g - group id
a - artifact id
v - version
p - packaging
c - classifier (optional, not shown in examples above)
file - each file to be uploaded, use one file parameter per file.
Note: Uploading via the REST API requires that the user has the "artifact upload" privilege in Nexus, in addition to create and update privileges on the target repository.
Enable the Nexus Unpack Plugin
In Nexus Professional 2.7.x+, the plugin is already installed by default.
In Nexus Professional 2.6.x and earlier, the optional plugin needs to be installed. You can enable this plugin in earlier versions of Nexus Professional by moving "$NEXUS_HOME/nexus/WEB-INF/optional-plugins/nexus-unpack-plugin-<version>" into "$NEXUS_HOME/nexus/WEB-INF/plugin-repository" and restarting the server.
In Nexus OSS you need to manually install the plugin. Download the bundle.zip which matches your nexus version, and unpack it in $NEXUS_HOME/nexus/WEB-INF/plugin-repository. Then restart the server.
Use the Nexus Unpack Plugin
Once enabled, you can use a REST endpoint to upload zip files via PUT request.
Required: Ensure that there is no trailing slash in the URL used):
So for example, using curl:
curl --upload-file my.zip -u admin:admin123 -v http://localhost:8081/nexus/service/local/repositories/releases/content-compressed/foo/bar
The files will be unpacked and deployed individually on the server side, just as if they had been individually deployed from a client using standard deploy mechanisms.
If the zipped file has a directory structure of "com/company/project/...", then you want to deploy to the root level of repository.
curl --upload-file my.zip -u admin:admin123 -v http://localhost:8081/nexus/service/local/repositories/releases/content-compressed
If the zipped file has a directory structure example of "project/...", then you want to deploy to the "com/company" level of repository.
curl --upload-file my.zip -u admin:admin123 -v http://localhost:8081/nexus/service/local/repositories/releases/content-compressed/com/company
Note that the user performing this deploy must have the "Unpack" privilege in Nexus, as well as create privileges in the target repository.
Also note that the files in the zip must be in the standard repository layout of the target repository.
Uploading using Powershell
There is an external guide which describes how to upload artifacts using Powershell.