maven settings

本文深入解析了Maven配置文件settings.xml的主要元素及其用途,包括本地仓库、交互模式、代理设置、服务器认证、下载镜像、激活配置文件、插件仓库等关键部分。了解这些设置对于优化Maven构建流程至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Settings

This is a reference for the user-specific configuration for Maven.

Includes things that should not be distributed with the pom.xml file, such as developer identity, along with local settings, like proxy information.

The default location for the settings file is ~/.m2/settings.xml

An XSD is available at:

<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <localRepository/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>

  <proxies>
    <proxy>
      <active/>
      <protocol/>
      <username/>
      <password/>
      <port/>
      <host/>
      <nonProxyHosts/>
      <id/>
    </proxy>
  </proxies>

  <servers>
    <server>
      <username/>
      <password/>
      <privateKey/>
      <passphrase/>
      <filePermissions/>
      <directoryPermissions/>
      <configuration/>
      <id/>
    </server>
  </servers>

  <mirrors>
    <mirror>
      <mirrorOf/>
      <name/>
      <url/>
      <layout/>
      <mirrorOfLayouts/>
      <id/>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <activation>
        <activeByDefault/>
        <jdk/>
        <os>
          <name/>
          <family/>
          <arch/>
          <version/>
        </os>
        <property>
          <name/>
          <value/>
        </property>
        <file>
          <missing/>
          <exists/>
        </file>
      </activation>
      <properties>
        <key>value</key>
      <properties/>

      <repositories>
        <repository>
          <releases>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </releases>
          <snapshots>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </snapshots>
          <id/>
          <name/>
          <url/>
          <layout/>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <releases>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </releases>
          <snapshots>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </snapshots>
          <id/>
          <name/>
          <url/>
          <layout/>
        </pluginRepository>
      </pluginRepositories>
      <id/>
    </profile>
  </profiles>

  <activeProfiles/>
  <pluginGroups/>
</settings>

settings

Root element of the user configuration file.

ElementTypeDescription
localRepositoryStringThe local repository.
Default value is: ${user.home}/.m2/repository
interactiveModebooleanWhether Maven should attempt to interact with the user for input.
Default value is: true.
usePluginRegistrybooleanWhether Maven should use the plugin-registry.xml file to manage plugin versions.
Default value is: false.
offlinebooleanIndicate whether maven should operate in offline mode full-time.
Default value is: false.
proxies/proxy*List<Proxy>(Many) Configuration for different proxy profiles. Multiple proxy profiles might come in handy for anyone working from a notebook or other mobile platform, to enable easy switching of entire proxy configurations by simply specifying the profile id, again either from the command line or from the defaults section below.
servers/server*List<Server>(Many) Configuration of server-specific settings, mainly authentication method. This allows configuration of authentication on a per-server basis.
mirrors/mirror*List<Mirror>(Many) Configuration of download mirrors for repositories.
profiles/profile*List<Profile>(Many) Configuration of build profiles for adjusting the build according to environmental parameters.
activeProfiles/activeProfile*List<String>(Many) List of manually-activated build profiles, specified in the order in which they should be applied.
pluginGroups/pluginGroup*List<String>(Many) List of groupIds to search for a plugin when that plugin groupId is not explicitly provided.

proxy

The <proxy> element contains informations required to a proxy settings.

ElementTypeDescription
activebooleanWhether this proxy configuration is the active one.
Default value is: true.
protocolStringThe proxy protocol.
Default value is: http.
usernameStringThe proxy user.
passwordStringThe proxy password.
portintThe proxy port.
Default value is: 8080.
hostStringThe proxy host.
nonProxyHostsStringThe list of non-proxied hosts (delimited by |).
idStringNo description.
Default value is: default.

server

The <server> element contains informations required to a server settings.

ElementTypeDescription
usernameStringThe username used to authenticate.
passwordStringThe password used in conjunction with the username to authenticate.
privateKeyStringThe private key location used to authenticate.
passphraseStringThe passphrase used in conjunction with the privateKey to authenticate.
filePermissionsStringThe permissions for files when they are created.
directoryPermissionsStringThe permissions for directories when they are created.
configurationDOMExtra configuration for the transport layer.
idStringNo description.
Default value is: default.

mirror

A download mirror for a given repository.

ElementTypeDescription
mirrorOfStringThe server ID of the repository being mirrored, eg "central". This MUST NOT match the mirror id.
nameStringThe optional name that describes the mirror.
urlStringThe URL of the mirror repository.
layoutStringThe layout of the mirror repository. Since Maven 3.
mirrorOfLayoutsStringThe layouts of repositories being mirrored. This value can be used to restrict the usage of the mirror to repositories with a matching layout (apart from a matching id). Since Maven 3.
Default value is: default,legacy.
idStringNo description.
Default value is: default.

profile

Modifications to the build process which is keyed on some sort of environmental parameter.

ElementTypeDescription
activation ActivationThe conditional logic which will automatically trigger the inclusion of this profile.
properties/key=value*Properties(Many) Extended configuration specific to this profile goes here. Contents take the form of property.value
repositories/repository*List<Repository>(Many) The lists of the remote repositories.
pluginRepositories/pluginRepository*List<Repository>(Many) The lists of the remote repositories for discovering plugins.
idStringNo description.
Default value is: default.

activation

The conditions within the build runtime environment which will trigger the automatic inclusion of the parent build profile.

ElementTypeDescription
activeByDefaultbooleanFlag specifying whether this profile is active as a default.
Default value is: false.
jdkStringSpecifies that this profile will be activated when a matching JDK is detected.
os ActivationOSSpecifies that this profile will be activated when matching OS attributes are detected.
property ActivationPropertySpecifies that this profile will be activated when this System property is specified.
file ActivationFileSpecifies that this profile will be activated based on existence of a file.

os

This is an activator which will detect an operating system's attributes in order to activate its profile.

ElementTypeDescription
nameStringThe name of the OS to be used to activate a profile.
familyStringThe general family of the OS to be used to activate a profile (e.g. 'windows')
archStringThe architecture of the OS to be used to activate a profile.
versionStringThe version of the OS to be used to activate a profile.

property

This is the property specification used to activate a profile. If the value field is empty, then the existence of the named property will activate the profile, otherwise it does a case-sensitive match against the property value as well.

ElementTypeDescription
nameStringThe name of the property to be used to activate a profile.
valueStringThe value of the property to be used to activate a profile.

file

This is the file specification used to activate a profile. The missing value will be a the location of a file that needs to exist, and if it doesn't the profile must run. On the other hand exists will test for the existence of the file and if it is there will run the profile.

ElementTypeDescription
missingStringThe name of the file that should be missing to activate a profile.
existsStringThe name of the file that should exist to activate a profile.

repository

Repository contains the information needed for establishing connections with remote repository

ElementTypeDescription
releases RepositoryPolicyHow to handle downloading of releases from this repository
snapshots RepositoryPolicyHow to handle downloading of snapshots from this repository
idStringA unique identifier for a repository.
nameStringHuman readable name of the repository.
urlStringThe url of the repository.
layoutStringThe type of layout this repository uses for locating and storing artifacts - can be "legacy" or "default".
Default value is: default.

releases

Download policy

ElementTypeDescription
enabledbooleanWhether to use this repository for downloading this type of artifact.
Default value is: true.
updatePolicyStringThe frequency for downloading updates - can be "always", "daily" (default), "interval:XXX" (in minutes) or "never" (only if it doesn't exist locally).
checksumPolicyStringWhat to do when verification of an artifact checksum fails - warn, fail, etc. Valid values are "fail" or "warn".

snapshots

Download policy

ElementTypeDescription
enabledbooleanWhether to use this repository for downloading this type of artifact.
Default value is: true.
updatePolicyStringThe frequency for downloading updates - can be "always", "daily" (default), "interval:XXX" (in minutes) or "never" (only if it doesn't exist locally).
checksumPolicyStringWhat to do when verification of an artifact checksum fails - warn, fail, etc. Valid values are "fail" or "warn".

pluginRepository

Repository contains the information needed for establishing connections with remote repository

ElementTypeDescription
releases RepositoryPolicyHow to handle downloading of releases from this repository
snapshots RepositoryPolicyHow to handle downloading of snapshots from this repository
idStringA unique identifier for a repository.
nameStringHuman readable name of the repository.
urlStringThe url of the repository.
layoutStringThe type of layout this repository uses for locating and storing artifacts - can be "legacy" or "default".
Default value is: default.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值