公司需要在本地搭建Nexus远程资源仓库服务器,手工上传资源文件十分繁琐并且耗时长,基于此种情况,想要进行批量上传需要借助脚本命令,不过前期需要手工进行历史资源和新资源的对比,这一步不可省略,推荐SVN历史对比功能或BeyondCompare对比工具。接下来就是批量上传的步骤,请看下方内容......
1.新建批量本地仓库依赖(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}/{} ;
2.在maven本地仓库目录下创建 mavenimport.sh 脚本,并将上述内容添加进去脚本文件中。
在maven本地仓库目录下,右键打开 git 自带的 git bash Here命令窗口:
执行以下命令:
./mavenimport.sh -u 用户名 -p 密码 -r http://localhost:8080/repository/仓库名/
执行完成后的效果图:
注意事项:
1、删除本地maven仓库目录下所有的 .lastUpdated 文件2、如果上传失败,可以将本地maven仓库目录下所有的 _remote.repositories 文件删除