Nexus 支持批量上传工件吗?

发布于 2024-08-04 01:33:01 字数 38 浏览 6 评论 0原文

我想知道我们是否可以将工件批量上传到 Nexus 的存储库中。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

巾帼英雄 2024-08-11 01:33:01

您可以通过多种方式完成此操作:

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.
旧城烟雨 2024-08-11 01:33:01

使用 Nexus 存储库转换工具创建版本和基于本地 .m2 文件夹的快照文件夹,然后将这些文件夹的内容移至 [sonatype-work]/storage/[repository-name]。

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].

韵柒 2024-08-11 01:33:01

首先使用我的脚本

#!/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'

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'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文