首页 > 其他分享 >Maven配置多仓库

Maven配置多仓库

时间:2023-01-17 12:55:14浏览次数:46  
标签:maven http 仓库 配置 Maven sec org true public

出于安全的考虑,maven 默认是不会去使用 snapshot 包的,所以,如果你有需要使用 snapshot 包(很多公司可能大量使用),那么你就需要配置 SNAPSHOT 为允许了

<repository>
          <id>central</id>
          <url>http://central</url>
          <releases>
                <enabled>true</enabled>
          </releases>
          <!-- 如下开启 snapshots 功能 -->
          <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
          </snapshots>
</repository>

激活配置

<activeProfiles>
    <!-- 此处是多个仓库的配置 -->
    <activeProfile>nexus</activeProfile>
</activeProfiles>

注意: 最后一个 activeProfiles 的属性是必须的,否则你可能发现你改了配置没有用

完整配置参考

<?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>${user.home}/.m2/repository</localRepository>
  <servers>
    <!-- 账号信息保留,私服使用 -->
    <server>
        <id>sec@public-snapshots</id>
        <username>snapshot_user</username>
        <password>snapshot123</password>
    </server>
    <server>
        <id>mirror-sec</id>
        <username>snapshot_user</username>
        <password>snapshot123</password>
    </server>
  </servers>

  <!-- 注释掉该mirror 配置项 -->
  <!-- <mirrors>
    <mirror>
      <id>mirror-sec</id>
      <mirrorOf>sec@public-snapshots,mirror-sec</mirrorOf>
      <url>http://maven.sec-ins.com.cn/repository/maven-public/</url>
    </mirror>
  </mirrors>
  -->
 
  <profiles>
   <profile>
      <id>sec</id>
      <!-- 注释掉该默认激活,统一在 activeProfiles 中配置-->
      <!-- <activation>
          <activeByDefault>true</activeByDefault>
      </activation> -->
      
      <repositories> 
        <!-- 直接添加一个 repository, 运行maven更新时,就会先尝试使用该repo进行拉取了
            可添加任意多个仓库,但如果网络不通,这样会导致很长时间的切换重试,可在ide中查看maven正在尝试哪个repository
        -->  
        <repository>    
            <id>repo1</id>    
            <name>org.maven.repo1</name>    
            <layout>default</layout>  
            <url>https://repo1.maven.org/</url>
            <!-- <url>http://maven.aliyun.com/nexus/content/groups/public</url> -->   
            <snapshots>    
                <enabled>false</enabled>    
            </snapshots>    
        </repository>
        <!-- 公司的配置保留,添加自定义的仓库即可 -->
           <repository> 
            <id>sec@public-snapshots</id> 
            <name>sec-snapshots</name> 
            <url>http://maven.sec-ins.com.cn/repository/maven-public</url> 
            <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
                <checksumPolicy>warn</checksumPolicy>
            </releases> 
            <snapshots>
                <enabled>true</enabled>
            </snapshots> 
        </repository>
      </repositories>
      </profile>
      <!-- 注释掉该plugin 配置 -->
      <!-- <pluginRepositories> 
        <pluginRepository> 
            <id>sec@public-snapshots</id> 
            <name>sec_plugin</name> 
            <url>http://maven.sec-ins.com.cn/repository/maven-public</url> 
            <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
                <checksumPolicy>warn</checksumPolicy>
            </releases> 
            <snapshots>
                <enabled>true</enabled>
            </snapshots> 
        </pluginRepository>       
       </pluginRepositories>
       -->
    <!-- 你也可以另开一个 profile, 保存自定义的 repositories, 在 activeProfiles 里加上此id 即可遍历以下 repository -->
   <profile>
      <id>my-profile</id>
      <repositories>    
        <repository>
            <id>alirepo1</id>    
            <name>org.maven.repo1</name>    
            <layout>default</layout>  
            <!-- <url>https://repo1.maven.org/</url> -->
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
            <snapshots>    
                <enabled>false</enabled>    
            </snapshots>    
        </repository>
        
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>repository.springframework.maven.release</id>
            <name>Spring Framework Maven Release Repository</name>
            <url>http://maven.springframework.org/milestone/</url>
        </repository>
        <repository>
            <id>org.springframework</id>
            <url> http://maven.springframework.org/snapshot</url>
        </repository>
        <repository>
            <id>spring-milestone</id>
            <name>Spring Maven MILESTONE Repository</name>
            <url>http://repo.spring.io/libs-milestone</url>
        </repository>
        <repository>
            <id>spring-release</id>
            <name>Spring Maven RELEASE Repository</name>
            <url>http://repo.spring.io/libs-release</url>
        </repository>
      </repositories>
      </profile>
  </profiles>

  <activeProfiles>
    <!-- 添加此属性,需要激活自定义的repo 的profile配置 -->
      <activeProfile>sec</activeProfile>
      <activeProfile>my-profile</activeProfile>
  </activeProfiles>
</settings>

欢迎关注作者微信公众号

 

 

标签:maven,http,仓库,配置,Maven,sec,org,true,public
From: https://www.cnblogs.com/zhanqing/p/mavenRepository.html

相关文章

  • JVM DNS 缓存配置(转)
    原文:https://www.jianshu.com/p/048e8bd3ea46作者:EricAlpha域名解析并非一个简单的过程,其解析结果可能会被层层缓存,如浏览器DNS缓存、操作系统DNS缓存、ISP的DNS......
  • ElasticSearch7.10配置Search-Guard之配置用户
    ElasticSearch7.10配置Search-Guard之配置用户配置sg_internal_user.yml密码是:elasticjode:hash:$2y$12$nUzkcjdnufzvI1HlmN7xSuND3skGhmwV5le5IINejz.asMFpLYNRy......
  • 【电力系统】基于粒子群算法求解热电联产系统优化配置问题附matlab代码
    ✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。......
  • Spring Boot 配置文件
    SpringBoot配置文件SpringBoot官方提供了两种常用的配置文件格式,分别是properties、yml格式。相比于properties来说,yml更加年轻,层级也是更加分明。properties和yml......
  • linux环境变量配置方式
    Linux环境变量配置的6种方法,建议收藏!Docker中文社区 2022-12-1408:00 发表于陕西 责编:Linux妹|来源:http://uusama.com/927.htmlLinux环境变量配置......
  • nginx 配置文件解析
    #usernobody;#工作进程数,一般设置为cpu核心数worker_processes4;worker_rlimit_nofile65535;#error_loglogs/error.log;#error_loglogs/error.lognotice......
  • crond系统计划任务的原理与配置
    关于Linux下的crontab,你不知道的那些知识点土豆居士 一口Linux 2022-12-1212:03 发表于江苏收录于合集#linux108个#crontab1个点击左上方蓝色“一口Lin......
  • maven 私服源配置 阿里云源配置
    1.源的优先级配置1.1,查看系统maven配置目录命令:mvn-v安排目录是:/usr/local/Cellar/maven/3.8.7/libexec/conf/settings.xml1.2,用户所在配置目录~/.m2/settings.......
  • pycharm下载安装与基本配置
    pycharm下载安装与基本配置1.简介 PyCharm是一种PythonIDE(IntegratedDevelopmentEnvironment,集成开发环境),带有一整套可以帮助用户在使用Python语言开发时提高其效率......
  • python解释器下载安装与配置环境变量
    python解释器下载安装与配置环境变量python解释器的下载安装历史:据说是荷兰的龟叔在圣诞节时无聊开发出来的python版本: 1)python1.X:初代版本几乎不用2)pyth......