zoukankan      html  css  js  c++  java
  • maven多仓库配置(公司服务器与阿里云仓库)

    1. 问题描述

    公司内网搭建的有maven私有服务器,但是碰到好几次只有gav没有jar的情况或者最新版本更新不及时,所以需要公司服务器和远程仓库(阿里云)相结合来满足项目需求。

    2. 解决方案:

    maven仓库配置主要两种方式,一种是全局的;一种是配置在项目中,局部的。

    2.1 方式一,全局配置

    直接更改repo中的setting,目前项目中正在使用(隐藏替换了公司服务器地址)。

    直接上代码

    <?xml version="1.0" encoding="UTF-8"?>
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
               <!-- <localRepository>E:Developmaven_repo</localRepository> -->    
        <localRepository>E:m2
    epository</localRepository>      
        <servers>
            <server>
            <id>releases</id>
            <username>admin</username>
            <password>admin@123</password>
        </server>
        <server>
            <id>snapshots</id>
            <username>admin</username>
            <password>admin@123</password>
        </server>
        </servers>
        <profiles>
            <profile>
                <id>nexus</id>
                <repositories>
                    <repository>
                        <id>central</id>
                        <url>http://dev.hbusy.com/maven/content/repositories/public</url>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy> 
                        </releases>
                        <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </snapshots>
                    </repository>
                    <repository>
    			              <id>cloudera</id>
    		           <url>https://repository.cloudera.com/artifactory/clouderarepos/</url>
    		            </repository>
    		            	<!--新增阿里云-->
    		             <repository>
    			              <id>aliyun</id>
    			              <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    		            </repository>
                </repositories>
                <pluginRepositories>
                    <pluginRepository>
                        <id>central</id>
                        <url>http://dev.hbusy.com/maven/content/repositories/public</url>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </releases>
                        <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </snapshots>
                    </pluginRepository>
                       <pluginRepository>
                        <id>aliyun</id>
                        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </releases>
                        <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </snapshots>
                    </pluginRepository>
                    
                </pluginRepositories>
            </profile>
                     
        </profiles>
        <activeProfiles>
            <activeProfile>nexus</activeProfile>
        </activeProfiles>
    </settings>
    

    配置解析:

    Maven 依赖搜索顺序:本地仓库->中央仓库->远程仓库。

    1.本地仓库指定

    <localRepository>E:m2
    epository</localRepository>  
    

    2. 国内一般直接用远程仓库(阿里云)

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

    3. 多仓库配置

    1. 配置多个repository
       <repositories>
      						<repository>
    			              <id>aliyun</id>
    			              <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    		            </repository>
       </repositories>
    
    1. 在pluginRepository中配置下对应的repository即可
      </pluginRepository>
                    
                       <pluginRepository>
                        <id>aliyun</id>
                        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </releases>
                        <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </snapshots>
                    </pluginRepository>
    

    2.2 方式二,项目中局部配置

    <project>
       <repositories>
                    <repository>
                        <id>central</id>
                        <url>http://dev.hbusy.com/maven/content/repositories/public</url>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy> 
                        </releases>
                        <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </snapshots>
                    </repository>
                    <repository>
    			              <id>cloudera</id>
    			              <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
    		            </repository>
    		            	<!--新增阿里云-->
    		             <repository>
    			              <id>aliyun</id>
    			              <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    		            </repository>
    </repositories>
    </project>
    

    ​ 实际开发过程中,一般使用全局配置(在repo中配置setting),除非有些新老项目共存的情况,jar包存在冲突,会单独在项目中配置下。


  • 相关阅读:
    6th Alpha阶段的postmortem报告
    两种open()函数
    文件操作权限第一位的0是什么意思
    vi的查找与替换
    浅析Linux下的/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc文件
    Linux命令总结:file
    Linux下/boot目录
    英语单词简记
    Linux下grep命令
    Linux下find命令
  • 原文地址:https://www.cnblogs.com/ruanjianlaowang/p/11182603.html
Copyright © 2011-2022 走看看