当前位置:   article > 正文

maven配置多仓库私服

maven配置多仓库私服

经常见我们除了需要官方的仓库以外,更多是配置了国内的阿里云公共仓库。但很多的企业会有自己的公共组件,两者会结合起来使用,就需要配置公司的私服。

而经常性的,我们会在 apache-maven-3.8.6\conf\settings.xml 中,标签中配置自己的仓库地址,这样的确起到了配置仓库的效果。

但是当我们在标签中配置多个mirror时,mirrorOf不能配置 . ,意思就是(根据mirrorOf和repository的id)匹配所有的库(repository),这样就是说如果你需要某个jar,他会从镜像地址去下载这个jar。不管你配置了多少个库,即使这些库的地址不一样,仍然会从镜像地址访问。
即:

<mirrorOf>*</mirrorOf> 
匹配所有仓库请求,即将所有的仓库请求都转到该镜像上

<mirrorOf>repo1,repo2</mirrorOf> 
将仓库repo1和repo2的请求转到该镜像上,使用逗号分隔多个远程仓库。 

<mirrorOf>*,!repo1</miiroOf> 
匹配所有仓库请求,repo1除外,使用感叹号将仓库从匹配中排除。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

这样的配置就比较麻烦,正常情况下我们只需要在项目拉取完毕的时候执行一次就可以了。

下面就提供另外一种配置多仓库多私服的方式!

我们不在标签中配置了。直接全部注释掉,然后到最后的标签中,创建多个profile即可。如下:

<profiles>
  <!--  部分注释代码已去除。  -->
	  <profile>
	      <id>jdk-1.8</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>aliyun</id>
	      <repositories>
	          <repository>
	              <id>aliyun</id>
	              <url>https://maven.aliyun.com/repository/public</url>
	              <releases>
	                  <enabled>true</enabled>
	              </releases>
	              <snapshots>
	                  <enabled>true</enabled>
	                  <updatePolicy>always</updatePolicy>
	              </snapshots>
	          </repository>
	      </repositories>
	  </profile>
	  <profile>
	      <id>nexus</id>
	      <repositories>
	          <repository>
	              <id>nexus</id>
	              <url>https://nexus.xxx.cn/repository/maven-group-warehouse/</url>
	              <releases>
	                  <enabled>true</enabled>
	              </releases>
	              <snapshots>
	                  <enabled>true</enabled>
	                  <updatePolicy>always</updatePolicy>
	              </snapshots>
	          </repository>
	      </repositories>
	  </profile>
  </profiles>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47

这种情况下,我们直接打开idea工具,在配置号maven的情况下,在右侧的maven区域的Profiles里面,就会多出现aliyun和nexus两个选项,对应到上面配置文件中的id。此时,我们在按照项目打包的时候,就可以按照我们的需要,自行勾选一下对应的仓库即可,无论多少个私服都可以这样去配置。
在这里插入图片描述

部分非主要内容参考借用了: https://blog.csdn.net/u014641168/article/details/123862963

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/135673
推荐阅读
相关标签
  

闽ICP备14008679号