跳至主要內容

maven私服批量上传本地依赖

Mr.keney2024年3月12日mavenmaven私服搭建nexus批量上传大约 2 分钟

maven本地仓库依赖上传到远程仓库

本地仓库上传到远程仓库

批量上传:

批量本地仓库依赖(jar包)上传脚本:

#!/bin/bash
# copy and run this script to the root of the repository directory containing files
# this script attempts to exclude uploading itself explicitly so the script name is important
# Get command line params
while getopts ":r:u:p:" opt; do
    case $opt in
        r) REPO_URL="$OPTARG"
        ;;
        u) USERNAME="$OPTARG"
        ;;
        p) PASSWORD="$OPTARG"
        ;;
    esac
done

find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;

在maven本地仓库目录下创建 batch_upload_repo2.sh 脚本,并将上述内容添加进去脚本文件中

在maven本地仓库目录下,右键打开 git 自带的 git bash Here命令窗口:

执行以下命令:

sh batch_upload_repo2.sh -u admin -p nxg_123456 -r http://localhost:8081/repository/nxgtest/

sh 脚本名称.sh -u 用户名 -p 密码 -r http://localhost:8081/repository/仓库名

执行完成是下图的效果:

注意事项

删除本地maven仓库目录下所有的 .lastUpdated 文件

如果上传失败,可以将本地maven仓库目录下所有的 _remote.repositories 文件删除

附件

参考:
本地仓库所有Jar批量上传到Nexus

基于自动化脚本批量上传依赖到nexus内网私服

批量上传本地maven库到Nexus服务器中

Maven内网开发使用离线仓库

持续集成工作原理 - maven私服