目录
问题一:jar上传至私服
第一步、找到Idea项目中指定maven配置的settings.xml文件,配置私服账号(snapshot和release都配)。配置如下:
第二步、在项目的pom.xml中配置私服地址和源码打包插件。注意,id与settings.xml中的账号的id对应,不然匹配不到。
问题二、jar下载从私服
配置只需一步骤:直接在项目的pom.xml中配置。
扩展三、解决下载jar慢问题
问题一、jar上传至私服
第一步:找到Idea项目中指定maven配置的settings.xml文件,配置私服账号(snapshot和release都配)。
备注:在<servers>标签中添加对应的账号。
<server>
<id>releases</id> <!-- 对应私服的releases仓库,注意是小写 -->
<username>admin</username> <!-- 私服用户名 -->
<password>54xxx</password> <!-- 私服密码 -->
</server>
<server>
<id>snapshots</id> <!-- 对应私服的releases仓库 -->
<username>admin</username>
<password>54xxx</password>
</server>
我的项目maven配置如图:
第二步:在项目的pom.xml中配置私服地址和源码打包插件。注意,id与settings.xml中的账号的id对应,不然匹配不到。
备注:直接在<project>标签中添加。
<distributionManagement>
<repository>
<id>releases</id> <!-- release地址-->
<name>nexus Repository RELEASES</name>
<url>http://nexus.xxx.cn/repository/xxx-releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id> <!-- snapshot地址-->
<name>nexus Repository SNAPSHOTS</name>
<url>http://nexus.xxx.cn/repository/xxx-snapshot/</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.0</version>
<!-- 绑定source插件到Maven的生命周期,并在生命周期后执行绑定的source的goal -->
<executions>
<execution>
<!-- 绑定source插件到Maven的生命周期 -->
<phase>compile</phase>
<!--在生命周期后执行绑定的source插件的goals -->
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
私服地址可以在nexus中copy,如图:
问题二、jar下载从私服
配置只需一步骤:直接在项目的pom.xml中配置。
备注:直接在<project>标签中添加。
<!-- 从私服下载jar包 -->
<repositories>
<repository>
<id>nexus</id> <!-- id可以随便取,只要url写对就可以了 -->
<!--
这里的url地址是nexus的组仓库地址,可以在nexus后台把其他仓库都添加到组中,如public
好处是:只用定义一个id就可以检索所有仓库的jar包
-->
<url>http://nexus.shandiantech.com/repository/maven-skio/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled> <!-- 允许从仓库中下载releases的jar包 -->
</releases>
<snapshots>
<enabled>true</enabled> <!-- 允许从仓库中下载snapshots的jar包 -->
<!-- 每次都会到私服中对比jar包是否发生了改变,若改变则下载最新的jar包都本地仓库;每次上传snapshots的jar包时都会有一个时间戳,因为snapshots是不稳定的随时都可能修改从新发布,所以这里需要配置成always,默认是:daily,每天更新 -->
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
扩展三、解决下载jar慢问题
另外下载jar慢,可以在settings.xml配置阿里云镜像地址,如:
备注:在<mirrors>标签中添加。
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus Aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>