本地项目通过maven deploy上传到nexus
1、在settings.xml中添加server信息
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>1234abcd</password>
</server>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>1234abcd</password>
</server>
2、在pom.xml中添加配置
<distributionManagement>
<repository>
<id>nexus-releases</id>
<url>http://27.196.38.203:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://27.196.38.203:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
id需要与settings.xml中的id相同,url是nexus中的仓库地址。
将.m2/repository上传私服nexus
1、在Nexus上新建Repository,选择maven2(hosted)方式,其它参数配置如下所示。
2、新建目录,名称任意(虚拟机:27.196.38.203)
mkdir /m2
将本地.m2/repository目录拷贝到新建目录下(通过winscp操作)
3、通过脚本执行导入(虚拟机:27.196.38.203)
cd /m2/repository
vi mavenimport.sh
#!/bin/bash
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}/{} ;
执行导入
chmod 777 mavenimport.sh
./mavenimport.sh -u admin -p 1234abcd -r http://27.196.38.203:8081/repository/app-public/
导入完成后可以看到
4、在setting.xml中配置mirror,从私服下载依赖
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<name>Nexus App Deploy</name>
<url>http://27.196.38.203:8081/repository/app-public/</url>
</mirror>