maven远程仓库访问顺序

首先需要了解一下各个配置文件,主要分为三类:

  1. 全局配置文件(${maven.home}/conf/settings.xml),maven安装路径下的/conf/settings.xml
  2. 用户配置文件(%USER_HOME%/.m2/settings.xml),windows用户文件夹下
  3. 项目配置文件:pom.xml

原文地址:What are the different types of profile? Where is each defined?

在这里插入图片描述
以上是mave下载依赖的大概过程,先会从本地仓库(${user.home}/.m2/repository 默认本地仓库)找,本地没有就会去远程仓库(https://repo.maven.apache.org/maven2/默认远程仓库)找。
仓库顺序原文地址:Profile Order
在这里插入图片描述
可能有些人不知道Parent POM和Super POM是什么意思,这里解释一下。
Parent POM:当前项目的父项目的pom文件
在这里插入图片描述
Super POM:顶级父pom,maven已经定义好的,就像java中所有类继承的Object一样,可能版本不一样有所不同。
以下是3.6.3的Super POM:

<project>
  <modelVersion>4.0.0</modelVersion>
 
  <repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>
 
  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
    </pluginRepository>
  </pluginRepositories>
 
  <build>
    <directory>${project.basedir}/target</directory>
    <outputDirectory>${project.build.directory}/classes</outputDirectory>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
    <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
    <scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>
    <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
    <resources>
      <resource>
        <directory>${project.basedir}/src/main/resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>${project.basedir}/src/test/resources</directory>
      </testResource>
    </testResources>
    <pluginManagement>
      <!-- NOTE: These plugins will be removed from future versions of the super POM -->
      <!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) -->
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-5</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.8</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.5.3</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
 
  <reporting>
    <outputDirectory>${project.build.directory}/site</outputDirectory>
  </reporting>
 
  <profiles>
    <!-- NOTE: The release profile will be removed from future versions of the super POM -->
    <profile>
      <id>release-profile</id>
 
      <activation>
        <property>
          <name>performRelease</name>
          <value>true</value>
        </property>
      </activation>
 
      <build>
        <plugins>
          <plugin>
            <inherited>true</inherited>
            <artifactId>maven-source-plugin</artifactId>
            <executions>
              <execution>
                <id>attach-sources</id>
                <goals>
                  <goal>jar-no-fork</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <inherited>true</inherited>
            <artifactId>maven-javadoc-plugin</artifactId>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <inherited>true</inherited>
            <artifactId>maven-deploy-plugin</artifactId>
            <configuration>
              <updateReleaseInfo>true</updateReleaseInfo>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
 
</project>
### 如何在 IntelliJ IDEA 中配置和使用 Maven 远程仓库 #### 修改 `settings.xml` 文件中的远程仓库地址 为了使 Maven 使用特定的远程仓库,比如阿里云中央仓库,可以编辑 Maven 的全局或用户级别的 `settings.xml` 文件。此文件位于 Maven 安装目录下的 `conf/settings.xml` 或者用户的 `.m2/` 目录内。 对于更方便的操作,推荐使用具备语法高亮特性的工具来打开并编辑该文件[^2]: ```xml <mirrors> <!-- mirror --> <mirror> <id>aliyunmaven</id> <name>Aliyun Maven</name> <url>https://maven.aliyun.com/repository/public</url> <mirrorOf>*</mirrorOf> </mirror> </mirrors> ``` 上述 XML 片段展示了如何定义一个镜像站点作为默认使用的远程仓库。通过指定 `<mirrorOf>*`, 表明所有的请求都将被导向至这个新的 URL 地址。 #### 设置 IDE 内部的 Maven 配置 除了调整外部的 `settings.xml` 外,在 IntelliJ IDEA 内也可以进行相应的设定以确保其识别到更新后的配置路径。进入 **File → Settings**, 对于 Windows/Linux 用户;或是 **IntelliJ IDEA → Preferences** 对 Mac OS X 用户而言,则可以在弹出窗口里定位到 **Build, Execution, Deployment → Build Tools → Maven** 下的相关选项卡[^3]: - 如果希望更改应用于所有项目而非单个项目的话,请选择左侧列表里的 "Other Settings". - 找到 “Maven home path”,确认指向的是期望版本的 Maven. - 查看“User settings file” 是否正确指定了自定义过的 `settings.xml`. - 确认勾选了覆盖本地存储库位置以及下载元数据和源码两项功能. 完成以上步骤之后点击 Apply 及 OK 来保存所做的改动。此时再执行任何依赖解析操作时,IDEA 就会依据最新的配置去访问所设置的远程仓库了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值