• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Maven | settings.xml
  1. Content of settings.xml
  2. Profile Configuration

  1. Content of settings.xml
    For comprehensive documentation on Maven settings, see: https://maven.apache.org/settings.html

    Maven's behavior can be customized through the "settings.xml" configuration file.

    Maven's distribution includes a global settings template located at "${MAVEN_HOME}/conf/settings.xml". This file contains global Maven configuration that applies to all users and builds on the system.

    You can create user-specific settings that override global configuration by placing a customized settings file at: "${user.home}/.m2/settings.xml".

    Maven processes settings in the following order of precedence:
    • User settings: ${user.home}/.m2/settings.xml (highest priority)
    • Global settings: ${MAVEN_HOME}/conf/settings.xml

    Here's a reference to the global template: settings.xml

    Key Elements of settings.xml:
    Element Description
    localRepository Specifies the path where Maven stores downloaded artifacts (dependencies, plugins, etc.).
    Default: ${user.home}/.m2/repository
    Example: <localRepository>/path/to/local/repo</localRepository>
    interactiveMode Controls whether Maven prompts for user input when needed
    Default: true
    Set to false for automated builds or CI/CD environments.
    offline When true, Maven operates in offline mode and won't attempt network connections to download artifacts.
    Default: false
    Useful when working without internet connectivity.
    pluginGroups Additional group IDs to search when resolving plugins by their prefix.
    Example: Adding org.springframework.boot allows using mvn spring-boot:run
    proxies Configuration for HTTP/HTTPS proxies when Maven needs to connect through corporate firewalls.
    Include host, port, username, password, and nonProxyHosts settings.
    servers Authentication credentials for accessing remote repositories and deployment targets.
    Contains server-id, username, password, and other authentication details.
    Use password encryption or environment variables for sensitive data.
    mirrors Repository mirrors that redirect artifact requests to alternative locations.
    Commonly used for corporate repositories or faster regional mirrors.
    Can mirror specific repositories or use * for all repositories.
    profiles Named sets of configuration that can be activated conditionally.
    Can contain repositories, plugin repositories, properties, and plugin configuration.
    Activated by conditions like JDK version, OS, system properties, or explicitly by name.
    activeProfiles List of profile IDs that are automatically active for all builds.
    Profiles listed here don't require explicit activation.
    Use sparingly as they apply globally.

    Best Practices:
    • Use profiles for environment-specific settings (development, staging, production).
    • Avoid putting project-specific configuration in settings.xml (use pom.xml instead).
    • Store sensitive information like passwords using Maven's password encryption feature.
  2. Profile Configuration
    Profiles in settings.xml allow you to create environment-specific configurations that can be activated based on various conditions.

    Profile Activation:
    Activation Type Description
    By Default Activated automatically unless deactivated.
    <activeByDefault>true</activeByDefault>
    By JDK Version Activate based on Java version.
    <jdk>23</jdk>
    <jdk>[1.8,)</jdk>
    By OS Activate based on operating system.
    <os><family>windows</family></os>
    By Property Activate when system property exists.
    <property><name>env</name><value>dev</value></property>

    You can Explicitly activate with -P PROFILE-ID: mvn clean install -P dev
© 2025  mtitek