我们可以在项目的POM中配置仓库和插件仓库,当然如果我们想要所有的Maven项目都使用私服,可以在settings.xml中配置,但是settings.xml并不直接支持配置repositories和pluginRepositories,但是Maven提供了profiles下的profile可以让我们定义一系列的配置信息,然后指定其激活条件,能够定义在settings.xml中的信息有<repositories>、<pluginRepositories>和<properties>。定义在<properties>里面的键值对可以在pom.xml中使用,这里我们配置远程仓库的地址和插件仓库。
<profiles>
<profile>
<id>jdk8</id>
<activation>
<activebydefault>true</activebydefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerversion>1.8</maven.compiler.compilerversion>
</properties>
</profile>
<profile>
<id>nexusRep</id>
<repositories>
<repository>
<id>nexus</id>
<name>Nexus Repository</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<!-- snapshot默认是关闭的,需要手动开启 -->
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>Nexus pluginRepository</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<!--maven设置的远程中央工厂不能下载snapshots的jar,这里覆盖一下-->
<profile>
<id>centralProfile</id>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<!--mirror设置url,这里不起作用-->
<url>https://repo1.maven.org/maven2/</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
但是Maven除了从Nexus上下载构件之外,还会时不时从中央仓库下载构件,然而这应该是Nexus的工作,所以我们需要配置一个镜像,用
<mirrorof>*</mirrorof>将Maven任何构件下载的请求都转发到私服中。
<mirrors>
<mirror>
<id>nexus</id>
<mirrorof>*</mirrorof>
<name>A Local Nexus Server</name>
<url>http://1localhost:8081/nexus/content/groups/public/</url>
</mirror>
</mirrors>
注意:在这里配置了镜像,那在<profiles>里配置的远程仓库的<url>就失效了,有效的是<releases>和<snapshots>元素。
当Maven需要下载发布版或者快照版构件的时候,他会首先检查我们配置的远程仓库中的<releases>和<snapshots>元素,看该类型的构件是否可以下载,如果可以下载,就转到镜像地址去下载。
上面的profile配置以后,还要进行激活,否则不生效
<!-- 激活 profile 配置 -->
<activeProfiles>
<!--<activeProfile>nexusProfile</activeProfile>-->
<activeProfile>centralProfile</activeProfile>
</activeProfiles>
使用Maven部署构件到Nexus:
在项目正常开发中,快照版本的构件可以部署到Nexus中策略为Snapshot的例如:maven-snapshots宿主仓库中,发布版本可以部署到Nexus中策略为Release的例如:maven-releases宿主仓库中,项目的POM文件配置如下:
<!-- 发布项目到nexus -->
<distributionManagement>
<repository>
<id>user-release</id>
<name>user release repo</name>
<url>http://localhost:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>user-snapshot</id>
<name>user snapshot repo</name>
<url>http://localhost:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
- ID名称必须要与settings.xml中Servers配置的ID名称保持一致。
- 项目版本号中有SNAPSHOT标识的,会发布到Nexus Snapshots Repository, 否则发布到Nexus Release Repository,并根据ID去匹配授权账号。
Nexus仓库对于匿名用户是只读的,所以为了能够部署构件,还需要在settings.xml文件中配置认证信息。
<server>
<id>user-release</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>user-snapshot</id>
<username>admin</username>
<password>admin123</password>
</server>
- nexus-releases: 用于发布Release版本
- nexus-snapshots: 用于发布Snapshot版本
- 在项目POM.xml中设置的版本号添加SNAPSHOT标识的都会发布为SNAPSHOT版本,没有SNAPSHOT标识的都会发布为Release版本。
- SNAPSHOT版本会自动加一个时间作为标识,如:4.3.0-SNAPSHOT发布后为变成4.3.0-SNAPSHOT-20160712.114532-1.jar
参考
https://blog.csdn.net/hellow__world/article/details/71855883
分享到:
相关推荐
详细介绍持续集成环境hudson+nexus+maven搭建
SVN-Jenkins-Nexus-Maven-Tomcat持续集成构建调研报告
使用maven、nexus、hudson、svn、sts进行持续集成开发环境搭建
持续集成环境maven+nexus+jenkins+svn搭建
Dubbo视频教程--基础篇--第14节--持续集成篇--Maven私有库和本地库的安装与配置(Sonatype Nexus + Maven)2.pdf
svn+maven+trac+nexus产品集成配置管理
nexus-3.19.1版本,包括mac、unix、win64系统。 Nexus是一个强大的Maven仓库...Nexus 使用ExtJS来开发界面,利用Restlet来提供完整的REST APIs,通过m2eclipse与Eclipse集成使用。Nexus支持WebDAV与LDAP安全身份认证。
jenkins集成环境,maven + nexus,项目bug管理系统mantis
持续集成-Maven-nexus-SNV-jenkins架构
nexus是一个强大的maven仓库管理器,它极大的简化了本地内部仓库的维护和外部仓库的访问. nexus是一套开箱即用的系统不需要数据库,它使用文件系统加Lucene来组织数据 nexus使用ExtJS来开发界面,利用Restlet来...
Gitlab-maven-nexus-Mysql-sonar持续集成调研报告,包括各个系统的集成配置,属性调解
Nexus是一个强大的Maven仓库管理器,它极大地简化了自己内部仓库的维护和外部...Nexus 使用ExtJS来开发界面,利用Restlet来提供完整的REST APIs,通过m2eclipse与Eclipse集成使用。Nexus支持WebDAV与LDAP安全身份认证。
4、Jenkins持续集成MAVEN讲解 5、Jenkins持续集成JOB工程设置 6、Jenkins持续集成网站构建实战 7、Jenkins持续集成自动化部署一 8、Jenkins持续集成自动化部署二 9、Jenkins持续集成插件设置篇 10、Jenkins持续集成...
持续集成环境maven+nexus+jenkins+svn搭建[整理].pdf
最新版的maven私服安装包,nexus-3.27.0-03-win64.zip 。Nexus是一个强大的...Nexus 使用ExtJS来开发界面,利用Restlet来提供完整的REST APIs,通过m2eclipse与Eclipse集成使用。Nexus支持WebDAV与LDAP安全身份认证
Nexus是一个强大的Maven仓库管理器,它极大地简化了自己内部仓库的维护和外部...Nexus 使用ExtJS来开发界面,利用Restlet来提供完整的REST APIs,通过m2eclipse与Eclipse集成使用。Nexus支持WebDAV与LDAP安全身份认证。
官网下载 nexus-3.31.1-01-win64 版本;Nexus是一个强大的Maven仓库管理器,...Nexus 使用ExtJS来开发界面,利用Restlet来提供完整的REST APIs,通过m2eclipse与Eclipse集成使用。Nexus支持WebDAV与LDAP安全身份认证。
什么是持续集成、什么是容器化集成和部署、怎么样安装Jenkins、规避哪些坑、什么是Blue Ocean 什么是流水线技术、什么是Jenkins Piepeline流水线技术、怎么样写流水线脚本 如何实现串行部署、并行部署、单节点部署、...
此外,Nexus3还支持与各种流行的持续集成/持续部署(CI/CD)工具集成,进一步提升了开发流程的自动化水平。 综上所述,Nexus3作为一款功能强大的Maven仓库管理工具,在国内软件开发领域具有广泛的应用前景。