Maven:settings.xml示例

来自Wikioe
Eijux讨论 | 贡献2022年5月8日 (日) 05:10的版本 →‎配置
跳到导航 跳到搜索


示例一:central、central

central 仓库地址:https://repo.maven.apache.org/maven2/
阿里云 Maven 仓库地址:https://maven.aliyun.com/repository/public

阿里云 Maven 使用指南:https://developer.aliyun.com/mvn/guide

配置

settings.xml(展开/隐藏)

如上,配置了:

  1. 本地仓库路径为:“D:\Repository”;
  2. 一个 profile(dev),包含两个 repository(aliyun、central)、两个 pluginRepository(aliyun、central);
  3. 两个 mirror:(repo1、repo2),用作 repository(central)的镜像;
    • repo1、repo2 镜像可以更新索引,但不稳定且速度慢;
  4. 在 activeProfiles 中启用了 profile(dev);

效果

在 Eclipse 中:

Eclipse中的Maven仓库.png

在 IDEA 中:

Idea中的Maven仓库.png

示例二:nexus2/3

本地 nexus2:http://localhost:8090/nexus/content/groups/public/
本地 nexus3:http://localhost:8091/repository/maven-public/

配置

settings.xml(展开/隐藏)

如上,配置了:

  1. 本地仓库路径为:“D:\Repository”;
  2. 三个 server:
    1. Server(<id>nexus3</id>):登录 mirror 的用户名密码;
      • 其中 <id> 须对应:<mirror><id>
    2. Server(<id>releases</id>):项目上传 releases 版本的用户名密码;
      • 其中 <id> 须对应:项目“pom.xml”<distributionManagement><repository><id>
    3. Server(<id>snapshots</id>):项目上传 snapshots 版本的用户名密码;
      • 其中 <id> 须对应:项目“pom.xml”<distributionManagement> <snapshotRepository><id>
        项目“pom.xml”示例:
        	...
        	
        	<distributionManagement>
        		<repository>
        			<id>releases</id>
        			<name>maven-releases</name>
        			<url>http://localhost:8091/repository/maven-releases/</url>
        		</repository>
        
        		<snapshotRepository>
        			<id>snapshots</id>
        			<name>maven-snapshots</name>
        			<url>http://localhost:8091/repository/maven-snapshots/</url>
        		</snapshotRepository>
        	</distributionManagement>
        
        	...
        
  3. 一个 profile(dev):包含一个 repository(本地 nexus3)、一个 pluginRepository(本地 nexus3);
  4. 一个 mirror:用作所有仓库的镜像(本地 nexus3);
  5. 在 activeProfiles 中启用了 profile(dev);

【以上,仓库、镜像,都用“本地 nexus3”,所以重复了,可省略其一】

效果

在 Eclipse 中:

Eclipse中的Maven仓库 2.png

在 IDEA 中:

Idea中的Maven仓库 2.png

附:“${user.home}/.m2/settings.xml”备份

settings.xml(展开/隐藏)

如上,仅配置了:一个 mirror(alimaven)用作 repository(central)的镜像;

  • 如果不配置 Repository,则Maven 仍然有一个默认仓库“central”(存在于源码)