Maven之私服配置
一.配置从私服下载
从私服下载主要是将 central 库的下载地址从https://repo1.maven.org/maven2/修改为私服地址,比如http://localhost:8081/repository/maven-public/。然后配置好访问私服的用户名和密码即可。
了解settings.xml文件结构
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>
- localRepository: 配置本地存储库的位置,默认为
${user.home}/.m2/repository - interactiveMode: 是否与用户开启交互模式,默认为 true
- offline: 离线模式,默认为 false
- pluginGroups: 比如
<pluginGroup>org.eclipse.jetty</pluginGroup>, 默认有org.apache.maven.plugins and org.codehaus.mojo。 - servers: 配置私服的用户名和密码
- mirrors: mirror相当于一个拦截器,它会拦截maven对remote repository的相关请求,把请求里的remote repository地址,重定向到mirror里配置的地址。
- proxies: 代理配置
- profiles: 配置环境
- activeProfiles: 配置默认激活的环境
1-配置用户名和密码
<!-- 访问私服需要的用户名和密码 -->
<servers>
<server>
<id>repo-releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>repo-snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
2-配置profile
下面的私服地址是假的。
<!-- 配置 zero-rdc-repo -->
<profile>
<id>me-repo</id>
<repositories>
<!-- 配置的顺序决定了下载 jar 包的顺序 -->
<!-- 阿里云的 release 版本 -->
<repository>
<id>central</id>
<url>https://maven.aliyun.com/repository/central</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- 私服的 release 版本 -->
<repository>
<id>repo-releases</id>
<url>https://repo.rdc.aliyun.com/repository/release/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- 私服的 snapshot 版本 -->
<repository>
<id>repo-snapshots</id>
<url>https://repo.rdc.aliyun.com/repository/snapshot/</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<!-- 阿里云插件的 release 版本 -->
<pluginRepository>
<id>central</id>
<url>https://maven.aliyun.com/repository/central</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
这里的 repositories 如果不配置的话,默认会有一个 Maven 中央仓库的配置,同样 pluginRepositories 中如果没有配置的话,默认也是有一个 Maven 中央仓库的配置。
还有!如果 repositories 中没有配置 repository.id 是 central 的 repository,会自动增加一个 Maven 中央仓库的配置,并且是以追加的方式,也就是配置在 repositories 的最后一个。所以如果只配置了私服的 repository 情况下,就会先去私服中下载,私服中下载不到时再去追加上来的 Maven 中央仓库中下载。
3-配置 mirror
<!-- 配置拦截 repository 内的 url 进行重定向 -->
<mirrors>
<!-- 将 central 的请求重定向到阿里云的公共 Maven 仓库 -->
<!-- 其它的不重定向到阿里云 -->
<mirror>
<id>Nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>https://maven.aliyun.com/repository/central</url>
</mirror>
</mirrors>
这里的 mirror 类似于重定向操作,改变 repository 的 url 属性。
如果在 repositories 配置了 central 的地址,则这里不配置也可以!!!
注意,这里写的是central而不是*,是因为我们只想把 Maven 中央仓库的请求重定向到阿里云上,而不是把所有的请求都重定向到阿里云上。Maven 中央仓库仅仅是一个仓库,打开 https://mvnrepository.com/repos发现我们经常使用的https://repo1.maven.org/maven2/仅仅是众多仓库中的一个,只不过这个是比较大而全的仓库而已。如果我们把所有的请求都重定向到这个仓库,那么就会有依赖找不到。
疑问,求解答
还有一个问题就是当时我配置的是*,所以有https://repo.spring.io/libs-milestone/仓库的 jar 包下载不到,那么问题来了,我如果配置的是central,而 repositories 中也没有配置https://repo.spring.io/libs-milestone/ 这个 repository,它是如何找到的呢???
补充:我觉得是 Maven 有一个配置,在没有配置*的 mirror 时会自动查找https://mvnrepository.com/repos中的所有库是否含有这个包。
二. 配置部署到私服
部署到私服就简单了,在项目中的 pom.xml 文件中加入如下内容后,并将访问私服的用户名和密码配置好即可。
在 pom.xml 中加入配置:
<distributionManagement>
<repository>
<id>local-release</id>
<url>http://localhost:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>local-snapshot</id>
<url>http://localhost:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
然后在 settings.xml 文件中加入访问私服的用户名和密码:
<servers>
<server>
<id>local-release</id>
<username>snail</username>
<password>admin</password>
</server>
<server>
<id>local-snapshot</id>
<username>snail</username>
<password>admin</password>
</server>
</servers>
注意:repository.id 和 server.id 必须是一致的!!!
配置好之后,在项目中执行mvn clean deploy -Dmaven.test.skip即可部署到私服了。
Q:还有一个问题就是我是部署到 release 库了还是 snapshot 库了???
A:根据<version>1.0.0</version>中的内容是否是以-SNAPSHOT为结尾的进行区分,如果想发布到 snapshot 库则必须以-SNAPSHOT为结尾,否则就发布到了 release 库。
Maven之私服配置的更多相关文章
- maven仓库私服配置
私服访问地址:[[http://192.168.1.252:9080/nexus/content/groups/public/ 地址]] 1. 打开eclipse/myeclipse的maven插件: ...
- maven 私服 配置 转
3 . Nexus预置的仓库 点击左侧 Repositories 链接,查看 Nexus 内置的仓库: Nexus 的仓库分为这么几类: hosted 宿主仓库:主要用于部署无法从公共仓库获取的构件( ...
- Maven 私服配置 转
1.配置Nexus为maven的私服 第一种方式:在项目的POM中如下配置 <repositories> <repository> <id> ...
- 【Maven】---Nexus私服配置Setting和Pom
maven---nexus私服配置setting和pom 上一遍博客已经在linux服务器上,搭建好nexus私服了,博客地址:Linux搭建Nexus3.X私服 现在就需要配置setting.xml ...
- 配置Maven从私服下载构件
--------------------siwuxie095 配置 Maven 从私服下载构件 从 Nexus ...
- 配置maven从私服上下载构件
maven 本地setting.xml配置 <!--配置maven从私服上下载构件 --> <profiles> <profile> <repositorie ...
- Maven私服配置Setting和Pom文件
上一遍博客已经在linux服务器上,搭建好nexus私服了 现在就需要配置setting.xml和pom.xml来使nexus作为maven的私服.setting.xml文件在conf下面,pom.x ...
- maven学习笔记五(仓库搭建,私服配置)
实际项目中,我们往往都是多人开发,这个时候,假如一个项目有300多M.用的jar包有100多个.只要项目组来一个人就从中央仓库下载依赖的jar,这种下载一般都需要持续很久.而且中央仓库一般都是配置在外 ...
- 配置Nexus为maven的私服
1.配置Nexus为maven的私服 第一种方式:在项目的POM中如下配置 <repositories> <repository> <id>nexus_public ...
随机推荐
- linux系统创建windows启动盘
平时工作中用到linux的操作命令较多,因此为了方便,就给电脑装了双系统,一般工作的时候,都选择进入linux系统.但是今天有件工作之外的事情需要解决下:创建一个windows启动盘.如果按照往常来说 ...
- 【编程漫谈】PHP
PHP是个很古老的脚本技术了,当年CGI比较让人诟病,于是PHP横空出世.PHP即写即用特性,吸引了一大批粉丝,而且类似C语言的编程风格,让那些C程序员非常容易地转到这个平台上来.当然PHP刚出来的时 ...
- https知识汇总
状态码 含义 100 客户端应当继续发送请求.这个临时响应是用来通知客户端它的部分请求已经被服务器接收,且仍未被拒绝.客户端应当继续发送请求的剩余部分,或者如果请求已经完成,忽略这个响应.服务器必须在 ...
- Spring Boot Cli下载安装
本地下载地址: spring-boot-cli-2.1.8.RELEASE-bin.zip : https://pan.baidu.com/s/1GMyxj1PecsM4BG_hzoteVQ spr ...
- flutter textfield设置高度后内容区无法居中?
textfiled 设置高度后,内容永远无法居中,最后找到原因 decoration: 中有一个 contentPadding属性,设置这个属性对应的Padding值即可
- 我非要捅穿这 Neutron(四)Open vSwitch in Neutron
目录 文章目录 目录 前文列表 OvS In Neutron 网络拓扑 OvS In Neutron 网络实现模型 双节点混合平面网络 双节点网络拓扑 OvS Bridges 与初始流表项 OvS b ...
- 一张图搞懂Ajax原理
本文整理在,我的github上.欢迎Star. 原理 说起ajax,就不得不说他背后的核心对象XMLHttpRequest,而说到XMLHttpRequest我觉得,从它的readyState状态说起 ...
- swoole前置基础知识 进程间通信
进程间通信(IPC,InterProcess Communication)是指在不同进程之间传播或交换信息. IPC的方式通常有管道(包括无名管道和命名管道).消息队列.信号量.共享存储.Socket ...
- 继承以及Super
一个小小的总结,主要关注以下三个问题:ES5的继承方式,ES5的继承与ES6的继承的区别,ES6的super的几种使用方式以及其中this的指向. From http://supermaryy.com ...
- Django学习笔记(二)URL编写规则
先在根目录以及每个app内添加一个空白的urls.py(此处根目录指项目同名文件夹内).程序收到用户请求时,先在根目录的urls.py查找该URL属于哪个app,再从app的urls.py找到具体的U ...