Nexus supports Mass upload of artifacts?
Asked Answered
A

3

24

I wanted to know if we can have mass upload of artifacts to the repository in Nexus.

Ashcan answered 11/9, 2009 at 12:31 Comment(1)
See this answer for a Groovy script that achieves the same thing but using the standard deployment process: #3240977Volsci
C
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.
Cist answered 11/9, 2009 at 12:51 Comment(5)
in the latest version of nexus rebuilding the metadata is just right click on the repository in nexusPolik
I 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.Maxiemaxilla
Third 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.Bounteous
@Bounteous I have nexus-3.12.1-01. I am not able to find storage folder.Druggist
This 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'.Simms
R
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].

Riddle answered 6/4, 2011 at 1:2 Comment(1)
That link appears to be dead or to now require a login. This question has some information on how to use the tool, though: #4243977Ommiad
D
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'
Distinctive answered 5/4, 2023 at 15:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.