quan的知识库

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

批量添加本地jar包至远程仓库

将maven本地仓库中的jar包用脚本上传到Nexus远程maven库中

如果是用的gradle管理工具,可以看我另一篇文章,先将jar包从gradle缓存中转移到maven本地库。

这里使用Bash脚本可以将Maven 本地库目录的所有jar , 一次性导入到Nexus中。 如果是在Windows环境中, 可以安装Git , 使用Git Bash 执行 sh 脚本。

在Maven的本地库路径下创建文件 mvnimport.sh, 内容如下

复制代码
#!/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 './mvnimport\.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}/{} ;
复制代码

如果本地仓库是在Windows系统下,则在该目录下右键执行Git Bash Here,否则直接下一步

执行如下命令:

./mvnimport.sh -u admin -p yourpassword -r http://localhost:8081/repository/maven-releases/

yourpassword改为你的密码

地址改为你的maven远程仓库的地址

 

posted on   quan的知识库  阅读(322)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示