maven 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>D:maven
epository</localRepository>
  <servers>
       <!-- 1、这里要配置配置上传用户及仓库信息 -->
        <server>
          <id>nexus</id>
          <username>admin</username>
          <password>xxxx</password>
        </server>
    </servers>
    
    <!-- 2、添加maven仓库镜像 -->  
    <mirrors>
        <mirror>
          <id>central-proxy</id>
          <mirrorOf>central</mirrorOf>
          <url>https://xxxx</url>
        </mirror> 
    </mirrors>
    
    <!-- 3、这种方式配置后所有本地使用该配置的maven项目的pom文件都无需配置私服下载相关配置。 -->
    <profiles>
        <profile>
             <id>mycof</id>
             <repositories>
                <repository>
                    <id>nexus</id>
                    <name>my's nexus</name>   
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                    <url>http://xxx/groups/public</url>
                </repository>
             </repositories> 
             <pluginRepositories>
            <!--插件库地址-->
           <pluginRepository>
              <id>nexus</id>
                <url>http://xxxx/groups/public</url>
              <releases>
                <enabled>true</enabled>
              </releases>
              <snapshots>
                <enabled>true</enabled>
               </snapshots>
            </pluginRepository>
          </pluginRepositories>
        </profile>

    </profiles>
       <!-/4、激活profile-->
            <activeProfiles>
              <activeProfile>mycof</activeProfile>
            </activeProfiles>
</settings>

当构建一个Maven项目时,首先检查pom.xml文件以确定依赖包的下载位置,执行顺序如下:

1、从本地资源库中查找并获得依赖包,如果没有,执行第2步。

2、如果在pom.xml中定义了自定义的远程仓库,那么也会在这里的仓库中进行查找并获得依赖包,如果没有,执行第3步。

3、从Maven默认*仓库中查找并获得依赖包(https://repo1.maven.org/maven2/),如果都没有找到,那么Maven就会抛出异常。

默认*仓库的地址:

1、http://repo1.maven.org/maven2/

默认的*仓库id为【central】, setting中<mirrorOf>central</mirrorOf>表示不再从默认*仓库中获取jar,一般为公司私服地址。

2、profiles 设置表示:设置一个指定的存储库地址。下载顺序为: 本地库->profiles地址->*仓库【有mirrorOf则从mirror地址下载,不会再查询默认的*仓库】

配置server:

是向私服上传jar时使用,id 一 一对应,项目中需要在pom.xml中配置如下

    <distributionManagement>
        <repository>
            <id>nexus</id>
            <name>releases</name>
            <url>http://xxx/content/repositories/releases</url>
        </repository>

        <snapshotRepository>
            <id>nexus</id>
            <name>snapshots</name>
            <url>http://xxx/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>