maven配置nexus私服详解
- 简介:
- 配置步骤
- 1、本地maven settings.xml配置
- 1.1配置本地仓库位置
- 1.2 server配置
- 1.3 镜像配置
- 1.4 私服仓库配置
- 2、maven项目pom.xml配置
- 完整配置模板
简介:
前提是已经搭建好了私服,我们需要在本地maven中配置相关参数,连接私服作为仓库;
配置步骤
1、本地maven settings.xml配置
1.1配置本地仓库位置
本地仓库配置,建议配置在.m2文件夹下
<localRepository>C:\Users\lele\.m2\repository</localRepository>
1.2 server配置
主要为使用的ID单独配置账号密码;
这个id标签的名字自定义唯一即可,在后面的步骤中为使用到。
<servers><!-- 设置maven-releases的账号密码(id与项目POM中的distributionManagement元素id必须一样) --><server> <id>maven-releases</id> <username>your-username</username> <password>your-password</password> </server> <!-- 设置maven-snapshots的账号密码(id与项目POM中的distributionManagement元素id必须一样) --><server> <id>maven-snapshots</id> <username>your-username</username> <password>your-password</password> </server> <!-- 设置maven-central的账号密码 --><server> <id>maven-public</id> <username>your-username</username> <password>your-password</password> </server> </servers>
1.3 镜像配置
<id>标签
:要和上一步 标签中配置的一致;这样去连接镜像时才能获取到通过账号密码连接;
<name>标签
:名称自定义
<url>标签
: 私服中maven-public的地址
<mirrorOf>标签
: 指定为 central
<mirrors><!-- 镜像配置 --><mirror><id>maven-public</id><name>maven-public</name> <url>http://ip:host/repository/maven-public/</url><mirrorOf>central</mirrorOf></mirror></mirrors>
1.4 私服仓库配置
<profiles><profile><!-- 私服id --><id>Nexus</id><repositories><repository><id>maven-public</id><url>http://ip:host/repository/maven-public/</url><snapshots><enabled>true</enabled></snapshots><releases><enabled>true</enabled></releases></repository></repositories><!--指定插件下载地址--><pluginRepositories><pluginRepository><id>maven-public</id><url>http://ip:host/repository/maven-public/</url><snapshots><enabled>true</enabled></snapshots><releases><enabled>true</enabled></releases></pluginRepository></pluginRepositories> </profile></profiles><!--启动私服仓库 --><activeProfiles><activeProfile>Nexus</activeProfile></activeProfiles>
2、maven项目pom.xml配置
自动提交jar进私服,pom.xml文件中添加
id 要和setting.xml中配置的一致
<!--私服配置--><distributionManagement><repository><id>maven-releases</id><url>http://ip:host/repository/maven-releases/</url></repository><snapshotRepository><id>maven-snapshots</id><url>http://ip:host/repository/maven-snapshots/</url></snapshotRepository></distributionManagement>
运行mvn deploy即会提交jar进私服仓库。
完整配置模板
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd"><!--配置本地仓库地址--><localRepository>C:\Users\lele\.m2\repository</localRepository><pluginGroups><!-- pluginGroup| Specifies a further group identifier to use for plugin lookup.<pluginGroup>com.your.plugins</pluginGroup>--></pluginGroups><!-- proxies| This is a list of proxies which can be used on this machine to connect to the network.| Unless otherwise specified (by system property or command-line switch), the first proxy| specification in this list marked as active will be used.|--><proxies></proxies>
<!--配置账号--><servers><!-- 设置maven-releases的账号密码(id与项目POM中的distributionManagement元素id必须一样) --><server> <id>maven-releases</id> <username>your-username</username> <password>your_password</password> </server> <!-- 设置maven-snapshots的账号密码(id与项目POM中的distributionManagement元素id必须一样) --><server> <id>maven-snapshots</id> <username>your-username</username> <password>your_password</password> </server> <!-- 设置maven-public的账号密码 --><server> <id>maven-public</id> <username>your-username</username> <password>your_password</password> </server> </servers><mirrors><!-- 私服镜像配置 --><mirror><id>maven-public</id><name>maven-public</name> <url>http://ip:host/repository/maven-public/</url><mirrorOf>central</mirrorOf></mirror></mirrors><profiles><profile><!-- 私服id --><id>Nexus</id><!--指定仓库下载地址--><repositories><repository><id>maven-public</id><url>http://ip:host/repository/maven-public/</url><snapshots><enabled>true</enabled></snapshots><releases><enabled>true</enabled></releases></repository></repositories><!--指定插件下载地址--><pluginRepositories><pluginRepository><id>maven-public</id><url>http://ip:host/repository/maven-public/</url><snapshots><enabled>true</enabled></snapshots><releases><enabled>true</enabled></releases></pluginRepository></pluginRepositories> </profile>
</profiles>
<!--激活环境配置--><activeProfiles><activeProfile>Nexus</activeProfile></activeProfiles>
</settings>
maven标签 与详解
maven将源码包和jar一起打包并上传到私服