下述配置文件是maven的全局配置文件settings.xml。maven中settings.xml中servers标签的作用是什么?这个配置文件描述的信息为什么要所有开发人员共享呢?
<?xml version="1.0"?>声明规范
<settings>
<localRepository>D:/alibaba/.m2</localRepository>本地仓库的路径
<!--配置服务端的一些设置。一些设置如安全证书不应该和pom.xml一起分发。这种类型的信息应该存在于构建服务器上的settings.xml文件中。-->
<servers>
<server>
<!--这是server的id(注意不是用户登陆的id),该id与distributionManagement中repository元素的id相匹配。-->
<id>b2b.repo.server</id>
<!--鉴权用户名。鉴权用户名和鉴权密码表示服务器认证所需要的登录名和密码。 -->
<username>maven</username>
<password>secret</password>
</server>
<server>
<id>scm.deploy.account</id>
<username>maven</username>
<password>secret</password>
</server>
</servers>
<profiles>
<profile>
<id>alibaba</id>
<repositories>
<repository>
<id>central</id>
<name>Alibaba Repositories Group</name>
<url>http://repo.alibaba-inc.com/nexus/content/groups/alirepositiry/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Alibaba Plugin Repos Group</name>
<url>http://repo.alibaba-inc.com/nexus/content/groups/alirepositiry/</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<pluginGroups>
<pluginGroup>com.alibaba.org.apache.maven.plugins</pluginGroup>
<pluginGroup>com.alibaba.maven.plugins</pluginGroup>
</pluginGroups>
<activeProfiles>
<activeProfile>alibaba</activeProfile>
</activeProfiles>
</settings>
如果有搭建自己公司的maven私服,公司内部会把自己的公司的公共jar包上传到maven私服中。
如果私服配置了上传权限,servers标签需要给出授权信息。
使用方法
1.在maven的工程中,pom中使用ditributionManagement标签私服地址。
上面的例子,我们公司的私服地址是http://www.myrepository.com,配置了SNAPSHOT包的上传路径和RELEASE包的上传路径。
2.在maven的settings.xml中配置servers。
需要注意的是两处的id需要相互匹配。
帐号的权限都是私服配置的。上传到SNAPSHOT还是RELEASE是由项目的version决定的。
也可以使用ssh key的方式配置servers。
Maven对settings.xml配置的官方说明文档。官方链接
Maven对password进行加密配置的说明文档。官方链接