Half of the top-level settings
elements are simple values, representing a range of values which describe elements of the build system that are active full-time.
<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>${user.home}/.m2/repository</localRepository>
<interactiveMode>true</interactiveMode>
<offline>false</offline>
...
</settings>
${user.home}/.m2/repository
. This element is especially useful for a main build server allowing all logged-in users to build from a common local repository.true
if Maven should attempt to interact with the user for input, false
if not. Defaults to true
.true
if this build system should operate in offline mode, defaults to false
. This element is useful for build servers which cannot connect to a remote repository, either because of network setup or security reasons.This element contains a list of pluginGroup
elements, each contains a groupId. The list is searched when a plugin is used and the groupId is not provided in the command line. This list automatically contains org.apache.maven.plugins
and org.codehaus.mojo
.
<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">
...
<pluginGroups>
<pluginGroup>org.eclipse.jetty</pluginGroup>
</pluginGroups>
...
</settings>
For example, given the above settings the Maven command line may execute org.eclipse.jetty:jetty-maven-plugin:run
with the truncated command:
mvn jetty:run
Servers
The repositories for download and deployment are defined by the repositories
and distributionManagement
elements of the POM. However, certain settings such as username
and password
should not be distributed along with the pom.xml
. This type of information should exist on the build server in the settings.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">
...
<servers>
<server>
<id>server001</id>
<username>my_login</username>
<password>my_password</password>
<privateKey>${user.home}/.ssh/id_dsa</privateKey>
<passphrase>some_passphrase</passphrase>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration></configuration>
</server>
</servers>
...
</settings>
id
element of the repository/mirror that Maven tries to connect to.${user.home}/.ssh/id_dsa
) and a passphrase
, if required. The passphrase
and password
elements may be externalized in the future, but for now they must be set plain-text in the settings.xml
file.Note: If you use a private key to login to the server, make sure you omit the <password>
element. Otherwise, the key will be ignored.
A new feature - server password and passphrase encryption has been added to 2.1.0+. See details on this page
Mirrors<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">
...
<mirrors>
<mirror>
<id>planetmirror.com</id>
<name>PlanetMirror Australia</name>
<url>http://downloads.planetmirror.com/pub/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
...
</settings>
id
is used to differentiate between mirror
elements and to pick the corresponding credentials from the <servers>
section when connecting to the mirror.id
of the repository that this is a mirror of. For example, to point to a mirror of the Maven central
repository (https://repo.maven.apache.org/maven2/
), set this element to central
. More advanced mappings like repo1,repo2
or *,!inhouse
are also possible. This must not match the mirror id
.For a more in-depth introduction of mirrors, please read the Guide to Mirror Settings.
Proxies<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">
...
<proxies>
<proxy>
<id>myproxy</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy.somewhere.com</host>
<port>8080</port>
<username>proxyuser</username>
<password>somepassword</password>
<nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
</proxy>
</proxies>
...
</settings>
proxy
elements.true
if this proxy is active. This is useful for declaring a set of proxies, but only one may be active at a time.protocol://host:port
of the proxy, separated into discrete elements.The profile
element in the settings.xml
is a truncated version of the pom.xml
profile
element. It consists of the activation
, repositories
, pluginRepositories
and properties
elements. The profile
elements only include these four elements because they concerns themselves with the build system as a whole (which is the role of the settings.xml
file), not about individual project object model settings.
If a profile is active from settings
, its values will override any equivalently ID'd profiles in a POM or profiles.xml
file.
Activations are the key of a profile. Like the POM's profiles, the power of a profile comes from its ability to modify some values only under certain circumstances; those circumstances are specified via an activation
element.
<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">
<!-- ... -->
<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>21</jdk>
<os>
<name>Windows 10</name>
<family>Windows</family>
<arch>amd64</arch>
<version>10.0.19045.5247</version>
</os>
<property>
<name>mavenVersion</name>
<value>3.9.9</value>
</property>
<file>
<exists>${project.basedir}/file2.properties</exists>
<missing>${project.basedir}/file1.properties</missing>
</file>
</activation>
<!-- ... -->
</profile>
</profiles>
<!-- ... -->
</settings>
Activation occurs when all specified criteria have been met, though not all are required at once.
activation
has a built in, Java-centric check in the jdk
element. This will activate if the test is run under a jdk version number that matches the prefix given. In the above example, 21.0.1
will match. Ranges are also supported. See the maven-enforcer-plugin for more details about supported ranges.os
element can define some operating system specific properties shown above. See the maven-enforcer-plugin for more details about OS values.profile
will activate if Maven detects a property (a value which can be dereferenced within the POM by ${name}
) of the corresponding name=value
pair.profile
by the existence
of a file, or if it is missing
.The activation
element is not the only way that a profile
may be activated. The settings.xml
file's activeProfile
element may contain the profile's id
. They may also be activated explicitly through the command line via a comma separated list after the -P
flag (e.g. -P test
).
To see which profile will activate in a certain build, use the maven-help-plugin
.
mvn help:active-profiles
Properties
Maven properties are value placeholder, like properties in Ant. Their values are accessible anywhere within a POM by using the notation ${X}
, where X
is the property. They come in five different styles, all accessible from the settings.xml
file:
env.X
: Prefixing a variable with “env.” will return the shell's environment variable. For example, ${env.PATH}
contains the $path environment variable (%PATH%
in Windows).project.x
: A dot (.) notated path in the POM will contain the corresponding element's value. For example: <project><version>1.0</version></project>
is accessible via ${project.version}
.settings.x
: A dot (.) notated path in the settings.xml
will contain the corresponding element's value. For example: <settings><offline>false</offline></settings>
is accessible via ${settings.offline}
.java.lang.System.getProperties()
are available as POM properties, such as ${java.home}
.x
: Set within a <properties /> element or an external files, the value may be used as ${someVar}
.<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">
...
<profiles>
<profile>
...
<properties>
<user.install>${user.home}/our-project</user.install>
</properties>
...
</profile>
</profiles>
...
</settings>
The property ${user.install}
is accessible from a POM if this profile is active.
Repositories are remote collections of projects from which Maven uses to populate the local repository of the build system. It is from this local repository that Maven calls it plugins and dependencies. Different remote repositories may contain different projects, and under the active profile they may be searched for a matching release or snapshot artifact.
<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">
...
<profiles>
<profile>
...
<repositories>
<repository>
<id>codehausSnapshots</id>
<name>Codehaus Snapshots</name>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>http://snapshots.maven.codehaus.org/maven2</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>myPluginRepo</id>
<name>My Plugins repo</name>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>https://maven-central-eu....com/maven2/</url>
</pluginRepository>
</pluginRepositories>
...
</profile>
</profiles>
...
</settings>
true
or false
for whether this repository is enabled for the respective type (releases
or snapshots
).always
, daily
(default), interval:X
(where X is an integer in minutes) or never
.ignore
, fail
, or warn
on missing or incorrect checksums.default
or legacy
.Repositories are home to two major types of artifacts. The first are artifacts that are used as dependencies of other artifacts. These are the majority of artifacts that reside within central. The other type of artifact is plugins. Maven plugins are themselves a special type of artifact. Because of this, plugin repositories may be separated from other repositories (although, I have yet to hear a convincing argument for doing so). In any case, the structure of the pluginRepositories
element block is similar to the repositories
element. The pluginRepository
elements each specify a remote location of where Maven can find new plugins.
<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">
...
<activeProfiles>
<activeProfile>env-test</activeProfile>
</activeProfiles>
</settings>
The final piece of the settings.xml
puzzle is the activeProfiles
element. This contains a set of activeProfile
elements, which each have a value of a profile
id
. Any profile
id
defined as an activeProfile
will be active, regardless of any environment settings. If no matching profile is found nothing will happen. For example, if env-test
is an activeProfile
, a profile in a pom.xml
(or profile.xml
with a corresponding id
will be active. If no such profile is found then execution will continue as normal.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3