Regarding the priority issue of maven reading the settings.xml file

Today, I configured the setting_a.xml file under the .m2 path pointed to by maven's setting.xml file path in IDEA. At the same time, my maven3.6.3 is also placed in .m2.

[1] .m2 folder

[2] apache-maven-3.6.3 folder

Then, when packaging and publishing in IDEA, I found that the specified setting_a.xml file could not be read no matter what. The settings_a.xml pointed to in this IDEA does not take effect, and the dependencies cannot be uploaded to the specified warehouse.

This should be a problem with the priority of maven loading the setting.xml file. Go to maven official website and have a detailed introduction.

[3] Official website about the priority of reading the setting.xml file

The maven official website introduces the priority of maven loading the setting.xml file:

translate:

Quick overview

Elements in the file contain elements that are used to define values ​​that configure Maven execution in various ways, such as , but should not be tied to any specific project, or distributed to an audience. These values ​​include the local repository location, alternate remote repository server, and authentication information.settingssettings.xmlpom.xml

Files may be located in two locations:settings.xml

  • Maven installation:${maven.home}/conf/settings.xml

  • User installation:${user.home}/.m2/settings.xml

The former is also called global settings, and the latter is called user settings. If both files exist, their contents are merged and the user-specific one is dominant.settings.xmlsettings.xmlsettings.xml

Tip: If you need to create user-specific settings from scratch, the easiest way is to copy the global settings from the Maven installation to a directory. Maven's default is a template with comments and examples so that you can quickly adjust it to match your needs.${user.home}/.m2settings.xml

Here is an overview of the main elements:settings

<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/>
  <offline/>
  <pluginGroups/>
  <servers/>
  <mirrors/>
  <proxies/>
  <profiles/>
  <activeProfiles/>
</settings>

The following expressions can be used:settings.xml

  1. ${user.home}and all other system properties (starting with Maven 3.0)

  2. ${env.HOME}etc. for environment variables

Note that properties defined in the configuration file cannot be used for interpolation.settings.xml

It roughly means:

settings.xml may exist in two folders:

  1.  Maven installation directory: ${M2_HOME}/conf/settings.xml

  2.  User's .m2 directory: ${user.home}/.m2/settings.xml

1 is global configuration and 2 is user configuration. If both exist, their contents will be merged and the user directory's settings.xml takes precedence.

The priority of loading setting.xml is as follows:

  1. Read settings.xml from the ${user.home}/.m2 directory

  2. When settings.xml does not exist in the ${user.home}/.m2 directory, it will be read from the {M2_HOME}/conf directory.

  3. Develop manually specified settings.xml in the idea interface

[4] Solution to the failure of reading the specified setting.xml

Method 1: Change the setting_a.xml file name in .m2 to the settings.xml file, and publish the jar package successfully (but if you continue to use the .m2/setting_a.xml path configuration in IDEA, the configuration will not take effect, and the file cannot be found).

Method 2: Leave the setting_a.xml file name in .m2 unchanged, directly delete the setting.xml file in the conf directory of maven3.6.3, and the release is successful.

Method 3: Delete the setting_a.xml file in .m2, modify the file to settings.xml and put it into the conf directory of maven3.6.3. Although the jar can be released successfully, the .m2/setting_a.xml configured in IDEA If the path configuration does not take effect, use the setting.xml file in the system variable.

Therefore, to be violent, delete the setting file in .m2 directly, and the environment and IDEA tools will use the setting configuration in the conf directory of maven3.6.3.

Done

Guess you like

Origin blog.csdn.net/qq_27706119/article/details/134341999