背景:在nexus webui界面上,只能一个一个导入文件,效率低下。于是搜罗了网上一些可靠性比较强的方法推荐给大家使用
1. 在nexus机器上, 找一个地方创建临时目录
mkdir -p /opt/nexus/repo/repository
2. 上传仓库包
scp 本地仓库 远程仓库
效果如下:
3. 编写批量上传脚本
vi /opt/nexus/repo/repository/mavenimport.sh
内容如下:
#!/bin/bash
```shell
# 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}/{} ;
- 执行脚本,上传仓库
/opt/nexus/repo/repository/mavenimport.sh -u admin -p admin -r http://{host}:8082/repository/maven-releases/
- 删除临时仓库(可以不删除,留着也没啥用)
rm -rf /opt/nexus/repo/repository