maven_配置多个仓库

1. 发生背景
 物联网开发计划结束,另一个项目那边有需求,于是让我们转个项目进行开发。然后在搭建新项目的时候,突然发现这个项目里面用到了自己私库的jar包,并且这些jar包在公库里找不到。

关键问题来了,就是配置多个仓库!

2. 失败的解决方法

我原本以为这个不就是在maven配置的时候加一个镜像就能解决的事情,结果并不是!

最初的样子如下:
maven_配置多个仓库_第1张图片
后面加了一个私库的镜像后,如下:maven_配置多个仓库_第2张图片

  • 结果只有没有找到私有的镜像中的包。后面去查资料才发现,配置多个mirror时,只有第一个才会生效。跟我想象的根本不一样。


3. 成功的解决方法
 解决方法:设置全局多仓库。
配置格式如下:

<profiles>
  	<profile>  
      <id>jdk-1.8id>  
      <activation>  
          <activeByDefault>trueactiveByDefault>  
          <jdk>1.8jdk>  
      activation>  
      <properties>  
          <maven.compiler.source>1.8maven.compiler.source>  
          <maven.compiler.target>1.8maven.compiler.target>  
          <maven.compiler.compilerVersion>1.8maven.compiler.compilerVersion>  
      properties>   
   profile>
  
	<profile>  
		<id>aliyunid>
		<repositories>
			<repository>
				<id>aliyunid>
				<url>http://maven.aliyun.com/nexus/content/groups/public/url>
				<releases>
					<enabled>trueenabled>
				releases>
				<snapshots>
					<enabled>trueenabled>
					<updatePolicy>alwaysupdatePolicy>
				snapshots>
			repository>
		repositories>   
   profile>
  
	<profile>  
		<id>Releasesid>
		<repositories>
			<repository>
				<id>Releasesid>
				<url>http://XX.XX.XX.XX:8081/nexus/content/repositories/releases/url>
				<releases>
					<enabled>trueenabled>
				releases>
				<snapshots>
					<enabled>trueenabled>
					<updatePolicy>alwaysupdatePolicy>
				snapshots>
			repository>
		repositories>   
   profile>
profiles>

 配置完profile后还要配置activeProfiles,其配置如下:

<activeProfiles>
		<activeProfile>ReleasesactiveProfile>
		<activeProfile>aliyunactiveProfile>
activeProfiles>

配置完之后,便可以重两个仓库中拉取jar包,如果一个仓库中不存在,便会从另一个仓库中去拉取jar包。

你可能感兴趣的:(maven)