将zip文件作为maven存储库导入Nexus OSS 3

时间:2016-06-07 13:07:43

标签: nexus

是否可以将zip文件导入为Nexus OSS 3中的Maven存储库?有一个关于迁移的文档部分(https://books.sonatype.com/nexus-book/reference/migrating.html),但它似乎不适用于Nexus 3,因为blob存储是一个blob ...... 在Artifactory上,它就像将zip文件上传到现有的repo一样简单...我认为它可以通过脚本完成,但我想知道是否有更简单的方法......

1 个答案:

答案 0 :(得分:2)

#!/bin/sh
#$1 - filepath of the local repo where the tree begins
#$2 - repo id like in settings.xml e.g. myrepo
#$3 - url of the repo eg. http://my-nexus.at:8081/repository/myrepo_releases/

MAVEN_EXECUTABLE="/apache-maven-3.3.9/bin/mvn"

if [ $# -eq 4 ]
then
    echo "Search in repo: $1"
    find $1 -type f -iname "*.jar" -print0 | while IFS= read -r -d $'\0' line; do
    relative_path_name="${line/$1/}"
    echo "RelativePathName: $relative_path_name"

    IFS='/' read -r -a array <<< "$relative_path_name"

    length=${#array[@]}

    pos=0;
    artifactidends=$((length -1 -2))    #-1 because auf array starts at 0 and length returns the count

    versionends=$((length -1 - 1))      #-1 because auf array starts at 0 and length returns the count
    version="${array[$versionends]}"
    filenameends=$((length -1))
    filename="${array[$filenameends]}"

    artifactIdVersion=${array[$artifactidends]}"-"$version

    ## find out classification
    classification="${filename/.jar/''}"
    classification="${classification/$artifactIdVersion/''}"

    if [[ ${classification:0:1} == "-" ]]
    then
        classification=${classification:1}
    fi

    groupends=$((length - 3))

    group=

    for element in "${array[@]}"
    do
        if [ $pos -lt $groupends ]
        then
            echo "GroupPart: ${array[$pos]}"
            group=$group"."${array[$pos]}
        fi
        pos=$((pos + 1))

    done
    group=${group:1}
    echo "Group: $group"

    if [ $group == "$4" ]
    then
        echo "$relative_path_name"
        echo "ArtifactId: ${array[$artifactidends]}"
        echo "Version: $version"
        echo "Classification: $classification"
        echo "Group: $group"

        mavencmd="$MAVEN_EXECUTABLE deploy:deploy-file -DgroupId=$group -DartifactId=${array[$artifactidends]} -Dversion=$version -Dclassifier=$classification -Dpackaging=jar -Dfile=./$relative_path_name -DrepositoryId=$2 -Durl=$3"
        echo "MavenCMD: $mavencmd"
        eval $mavencmd
        echo "upload done"
    else
        echo "upload not done (group does not match: $group)"
    fi
    echo -e ""
    echo -e ""
done
else
    echo "USAGE"
    echo -e ""
    echo "   * Call the command with params:"
    echo "      ./upload_all_to_nexus.sh localRepoFilepath repoId repoUrl groupToConsider"
    echo -e ""
    echo "   * Example:"
    echo "      ./upload_all_to_nexus.sh /tmp/not_local_repository/ myrepo http://my-nexus.at:8081/repository/repo my.group"

fi