I wanted to know if we can have mass upload of artifacts to the repository in Nexus.
Asked
Active
Viewed 1.9k times
24
-
See this answer for a Groovy script that achieves the same thing but using the standard deployment process: http://stackoverflow.com/questions/3240477/upload-download-entire-directory-to-nexus-through-maven – Aaron Digulla Aug 29 '11 at 08:37
3 Answers
16
You can do it in a variety of ways:
- Use the Nexus artifact upload page (note this only works for multiple artifacts with the same groupId and artifactId).
- Set up a script, with multiple invocations of the maven-deploy-plugin's deploy-file goal, one for each artifact.
- If you have access to the file system, you can copy the files directly into [sonatype-work]/storage/[repository-name]. If you do this, set up scheduled tasks to rebuild the metadata and reindex the repository.

Rich Seller
- 83,208
- 23
- 172
- 177
-
1in the latest version of nexus rebuilding the metadata is just right click on the repository in nexus – Chetan Dec 29 '12 at 10:22
-
1I would not consider the nexus upload page useful for mass upload of artifacts since the file dialog it pops-up only allows a single selection - so every artifact requires multiple button clicks which gets old very quickly. – Jay Mar 01 '13 at 16:46
-
1Third option worked like a champ, needed to click refresh a few times for it to pick up the changes on disk though. Just copy everything under the .../.m2/repository directory in the .../sonatype_work/nexus/storage/thirdparty directory. – cyber-monk Jul 12 '13 at 15:23
-
@cyber-monk I have nexus-3.12.1-01. I am not able to find storage folder. – Hiren Jun 18 '18 at 12:41
-
2This will not work for Nexus 3 and above. The local storage is not in the form of plain binary files anymore; everything is stored as 'blobs'. – shasan Feb 07 '19 at 20:04
3
Use the Nexus Repository Conversion Tool to create Release and Snapshot folders based on your local .m2 folder and then move the contents of those folders into [sonatype-work]/storage/[repository-name].

Taylor Leese
- 51,004
- 28
- 112
- 141
-
That link appears to be dead or to now require a login. This question has some information on how to use the tool, though: http://stackoverflow.com/questions/4243477/update-nexus-repository-with-local-artifacts – James Jul 07 '16 at 03:28
0
Use my script to begin with
#!/bin/bash
# this script needs a "artifacts" file right next to it. Create it by using following script in your .m2-folder
# find -iname "*.pom" -printf "%h\n" > files; find -iname "*.jar" -printf "%h\n" >> files; cat files | sort | uniq -u > artifacts; rm files
NEXUS_USERNAME="admin"
NEXUS_PASSWORD="nexus"
NEXUS_URL="localhost:8081"
cat artifacts | while read i; do
pompath=$(find $i -name *.pom)
jarpath=$(find $i -name *.jar)
# extracting metainformations from pom
groupId=$(echo $pompath | xargs xpath -e 'project/groupId/text()')
artifactId=$(echo $pompath | xargs xpath -e 'project/artifactId/text()')
version=$(echo $pompath | xargs xpath -e 'project/version/text()')
if test -z "$groupId"
then
echo "project-groupId is empty - using parent/groupId"
groupId=$(echo $pompath | xargs xpath -e 'project/parent/groupId/text()')
fi
if test -z "$version"
then
echo "project-version of jar-pom is empty - using parent/version"
version=$(echo $pompath | xargs xpath -e 'project/parent/version/text()')
fi
# choosing upload-strategy, preferring jar-upload
if test -z "$jarpath"
then
echo "uploading $artifactId as pom"
# a 400 error means that the artifactId already exists
mvn deploy:deploy-file \
-DgroupId=$groupId \
-DartifactId=$artifactId \
-Dversion=$version \
-Dpackaging=pom \
-Dfile=$pompath \
-Durl="http://${NEXUS_USERNAME}:${NEXUS_PASSWORD}@${NEXUS_URL}/repository/maven-releases/"
echo "uploading $pompath with groupId: $groupId; artifactId: $artifactId; version: $version"
else
echo "uploading $artifactId as jar"
# a 400 error means that the artifactId already exists
mvn deploy:deploy-file \
-DgroupId=$groupId \
-DartifactId=$artifactId \
-Dversion=$version \
-Dpackaging=jar \
-DgeneratePom=true \
-Dfile=$jarpath \
-Durl="http://${NEXUS_USERNAME}:${NEXUS_PASSWORD}@${NEXUS_URL}/repository/maven-releases"
echo "uploading $jarpath with groupId: $groupId; artifactId: $artifactId; version: $version"
fi
done
echo 'done uploading artifacts'

Kolja
- 21
- 8