美文网首页
2020-03-16 maven settings 配置随笔

2020-03-16 maven settings 配置随笔

作者: 艾比ab | 来源:发表于2020-03-16 22:55 被阅读0次

maven为了性能,做了多级的仓库(类似多级缓存)设计

本地仓库 ->  私服 -> 镜像 -> 中央仓库

本地仓库配置

<localRepository> xx </localRepository>

默认值: ${user.home}/.m2/repository

私服

私服是一个特殊的远程仓库,它是架设在局域网内的仓库服务。私服代理广域网上的远程仓库,供局域网内的Maven用户使用。当Maven需要下载构建的使用,它先从私服请求,如果私服上没有的话,则从外部的远程仓库下载(客户机器从远程仓库下载),然后缓存在私服上,再为Maven的下载请求提供服务。

配置

<profiles>

  <profile>

      <repositories><!--仓库-->

        <repository><!--仓库1-->

        ...

        </repository>

        <repository><!--仓库2-->

        ...

        </repository>

      </repositories>

      <pluginRepositories><!--插件仓库-->

        <pluginRepository></pluginRepository>

      <pluginRepositories>

  </profile>

</profiles>

在一个大的团队,建议不同的业务线配置不同的仓库。公共的资源共享同一个仓库。

镜像

为什么需要配置maven国内镜像?

1、在不配置镜像的情况下,maven默认会使用中央库.

2、maven中央库在国外,有时候访问会很慢,尤其是下载较大的依赖的时候,有时候速度会很慢,甚至会出现无法下载的情况.

3、为了解决依赖下载速度的问题,需要配置maven国内镜像

<mirror>

      <id>alimaven</id>

      <name>aliyun maven</name>

      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>

<mirrorOf>central</mirrorOf>       

设置代理

有时候你所在的公司基于安全因素考虑,要求你使用

通过安全认证的代理访问因特网。这种情况下,就需要

为maven配置http代理,才能让他正常访问外部畅快,以下载

所需要的资源。

<proxies>

    <proxy>

      ...

    </proxy>

</proxies>

私服的仓库访问权限控制。

支持两种方式密码,privateKey。

<servers>

    <server>

      <id>deploymentRepo</id> <!--id要跟 仓库的id匹配-->

      <username>repouser</username>

      <password>repopwd</password>

    </server>

<servers>

访问权限包括下载和上传(deploy)权限。 不同的账号赋予不同权限。

上传的配置,通常在pom.xml 根部配置

<distributionManagement>

    <snapshotRepository>

      <id>xxxxx</id>

          <name>Licai Snapshots RC</name>

          <url>http://xxxxx:7080/repository/xxxxx</url>

    </snapshotRepository>

</distributionManagement>

如果用户没有deploy的权限,执行deploy的时候,会报错。deploy的权限在settings.xml的severs标签里面配置。

参考

Maven的settings.xml文件结构详解

https://blog.csdn.net/taiyangdao/article/details/52274263

Maven:repositories、distributionManagement、pluginRepositories中repository的区别

https://blog.csdn.net/netyeaxi/article/details/95804076

相关文章

网友评论

      本文标题:2020-03-16 maven settings 配置随笔

      本文链接:https://www.haomeiwen.com/subject/dohaehtx.html