maven3.9的settings.xml 内容学习

settings.xml 文件介绍

settings.xml 是 Maven 的配置文件,它允许你自定义 Maven 的行为,比如设置仓库、代理、认证信息等。在 Maven 3.9 中,settings.xml 的结构和内容可能与之前的版本相似,但可能会有一些小的改进或变化。下面我们以3.9.6版本介绍。

首先打开maven的解压目录的 conf 文件夹

打开settings.xml文件

下面我们一个配置一个的过

settings.xml 配置项

总配置项(简化)

XML 复制代码
<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
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>
  <pluginGroups/>
  <servers/>
  <mirrors/>
  <proxies/>
  <profiles/>
  <activeProfiles/>
</settings>
localRepository

设置本地仓库的位置。

示例:

XML 复制代码
 <localRepository>D:\repository\.m2</localRepository>
interactiveMode

设置Maven是否应该以交互模式运行。默认值为true,表示Maven在需要时会提示用户输入。如果设置为false,Maven将使用默认值或基于其他设置的值。

示例:

XML 复制代码
  <interactiveMode>true</interactiveMode>
offline

<offline>设置Maven是否应该尝试联网执行构建。默认值为false。当由于网络设置或安全因素,构建服务器不能连接远程仓库时,这个设置非常有用。

示例:

XML 复制代码
  <offline>false</offline>
pluginGroups

定义插件组。<pluginGroups>允许定义额外的插件组,这些组在解析插件时会被搜索。默认情况下,Maven会自动添加org.apache.maven.pluginsorg.codehaus.mojo

示例:

XML 复制代码
  <pluginGroups>
    <pluginGroup>org.mortbay.jetty</pluginGroup>
  </pluginGroups>
servers

<servers>用于定义服务器配置,如认证信息,这些信息通常不应该在pom.xml中配置,以避免安全问题。

示例:

XML 复制代码
  <interactiveMode>true</interactiveMode>
mirrors

配置镜像站点,用于加速 Maven 下载。

配置阿里云镜像示例:

XML 复制代码
  <mirrors>
      <mirror>
          <id>alimaven</id>
          <name>aliyun maven</name>
          <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
          <mirrorOf>central</mirrorOf>
      </mirror>
  </mirrors>
proxies

<proxies>用于配置网络代理,当Maven需要通过代理服务器连接外部网络时使用。

示例:

XML 复制代码
<proxies>
  <proxy>
    <id>optional</id>
    <active>true</active>
    <protocol>http</protocol>
    <username>proxyuser</username>
    <password>proxypass</password>
    <host>proxy.host.net</host>
    <port>80</port>
    <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
  </proxy>
</proxies>
profiles

<profiles>定义了一组构建配置文件,每个<profile>可以包含不同的设置和插件组。<activation>子元素定义了激活该配置文件的条件。<activeProfiles>列出了需要激活的配置文件ID。

示例:

XML 复制代码
  <profiles>
    <profile>
      <id>tsetRepositories</id>
      <repositories>
        <repository>
          <id>tset</id>                                           
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>             
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
        
      </repositories>     
    </profile>
  </profiles>
activeProfiles

指定默认激活的配置文件。

示例:

XML 复制代码
  <activeProfiles>
    <activeProfile>testRepositories</activeProfile>
  </activeProfiles>

注意

settings.xml 文件通常位于你的用户目录下

在 Windows 上可能是 C:\Users\username

在 macOS 或 Linux 上可能是 ~/.m2

可以在命令行中使用 -s 参数指定一个不同的 settings.xml 文件。




相关推荐
ndjnddjxn1 天前
Rust学习
开发语言·学习·rust
菜鸟‍1 天前
【后端学习】MySQL数据库
数据库·后端·学习·mysql
陈天伟教授1 天前
基于学习的人工智能(1)机器学习
人工智能·学习
im_AMBER1 天前
Leetcode 59 二分搜索
数据结构·笔记·学习·算法·leetcode
专注于大数据技术栈1 天前
java学习--final
java·开发语言·学习
田里的水稻1 天前
AI_常见“XX学习”术语速查表
人工智能·学习
Nan_Shu_6141 天前
学习:Sass
javascript·学习·es6
天殇凉1 天前
AC自动机学习笔记
java·笔记·学习
AA陈超1 天前
从0开始学习 **Lyra Starter Game** 项目
c++·笔记·学习·游戏·ue5·lyra
likuolei1 天前
XML DOM - NodeList 对象
xml