ToB企服应用市场:ToB评测及商务社交产业平台

标题: Java Maven Settings配置参考 [打印本页]

作者: 欢乐狗    时间: 2023-7-24 01:46
标题: Java Maven Settings配置参考
介绍

快速概览

settings.xml文件中的 settings 元素包含用于定义以各种方式配置Maven执行的值的元素,如pom.xml,但不应绑定到任何特定项目或分发给受众。这些值包括本地仓库位置、备用远程仓库服务器和身份验证信息。
settings.xml文件可能位于两个地方:
前者的 settings.xml也称为全局设置,后者的 settings.xml称为用户设置。如果这两个文件都存在,它们的内容就会被合并,而用户特定的 settings.xml占主导地位。
提示:如果您需要从头开始创建特定于用户的设置,最简单的方法是将全局设置从Maven安装位置复制到${user.home}/.m2目录中。Maven的默认 settings.xml是一个包含注释和示例的模板,因此你可以快速调整它以满足您的需求。
以下是settings下的顶级元素概述:
  1. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  3.   <localRepository/>
  4.   <interactiveMode/>
  5.   <offline/>
  6.   <pluginGroups/>
  7.   <servers/>
  8.   <mirrors/>
  9.   <proxies/>
  10.   <profiles/>
  11.   <activeProfiles/>
  12. </settings>
复制代码
settings.xml的内容可以使用以下表达式进行插值(interpolated):
1.${user.home}和所有其他系统属性(自Maven 3.0以来)
2.${env.HOME}等环境变量
请注意,在settings.xml 中的profiles中定义的属性不能用于插值。
一个简单配置示例
  1.     D:\maven-repo<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  3.   <localRepository/>
  4.   <interactiveMode/>
  5.   <offline/>
  6.   <pluginGroups/>
  7.   <servers/>
  8.   <mirrors/>
  9.   <proxies/>
  10.   <profiles/>
  11.   <activeProfiles/>
  12. </settings>      testUser            APBNwz5vH2BK2Et9ujKQsWQQ245            central<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  13.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  14.   <localRepository/>
  15.   <interactiveMode/>
  16.   <offline/>
  17.   <pluginGroups/>
  18.   <servers/>
  19.   <mirrors/>
  20.   <proxies/>
  21.   <profiles/>
  22.   <activeProfiles/>
  23. </settings>          testUser            APBNwz5vH2BK2Et9ujKQsWQQ245            snapshots<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  25.   <localRepository/>
  26.   <interactiveMode/>
  27.   <offline/>
  28.   <pluginGroups/>
  29.   <servers/>
  30.   <mirrors/>
  31.   <proxies/>
  32.   <profiles/>
  33.   <activeProfiles/>
  34. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  35.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  36.   <localRepository/>
  37.   <interactiveMode/>
  38.   <offline/>
  39.   <pluginGroups/>
  40.   <servers/>
  41.   <mirrors/>
  42.   <proxies/>
  43.   <profiles/>
  44.   <activeProfiles/>
  45. </settings>*            maven            https://artifactory.example.com/artifactory/maven            maven<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  46.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  47.   <localRepository/>
  48.   <interactiveMode/>
  49.   <offline/>
  50.   <pluginGroups/>
  51.   <servers/>
  52.   <mirrors/>
  53.   <proxies/>
  54.   <profiles/>
  55.   <activeProfiles/>
  56. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  57.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  58.   <localRepository/>
  59.   <interactiveMode/>
  60.   <offline/>
  61.   <pluginGroups/>
  62.   <servers/>
  63.   <mirrors/>
  64.   <proxies/>
  65.   <profiles/>
  66.   <activeProfiles/>
  67. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  68.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  69.   <localRepository/>
  70.   <interactiveMode/>
  71.   <offline/>
  72.   <pluginGroups/>
  73.   <servers/>
  74.   <mirrors/>
  75.   <proxies/>
  76.   <profiles/>
  77.   <activeProfiles/>
  78. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  79.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  80.   <localRepository/>
  81.   <interactiveMode/>
  82.   <offline/>
  83.   <pluginGroups/>
  84.   <servers/>
  85.   <mirrors/>
  86.   <proxies/>
  87.   <profiles/>
  88.   <activeProfiles/>
  89. </settings>nexus-aliyun<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  90.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  91.   <localRepository/>
  92.   <interactiveMode/>
  93.   <offline/>
  94.   <pluginGroups/>
  95.   <servers/>
  96.   <mirrors/>
  97.   <proxies/>
  98.   <profiles/>
  99.   <activeProfiles/>
  100. </settings>  nexus-aliyun<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  101.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  102.   <localRepository/>
  103.   <interactiveMode/>
  104.   <offline/>
  105.   <pluginGroups/>
  106.   <servers/>
  107.   <mirrors/>
  108.   <proxies/>
  109.   <profiles/>
  110.   <activeProfiles/>
  111. </settings>  http://maven.aliyun.com/nexus/content/groups/public/<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  112.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  113.   <localRepository/>
  114.   <interactiveMode/>
  115.   <offline/>
  116.   <pluginGroups/>
  117.   <servers/>
  118.   <mirrors/>
  119.   <proxies/>
  120.   <profiles/>
  121.   <activeProfiles/>
  122. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  123.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  124.   <localRepository/>
  125.   <interactiveMode/>
  126.   <offline/>
  127.   <pluginGroups/>
  128.   <servers/>
  129.   <mirrors/>
  130.   <proxies/>
  131.   <profiles/>
  132.   <activeProfiles/>
  133. </settings>        true<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  134.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  135.   <localRepository/>
  136.   <interactiveMode/>
  137.   <offline/>
  138.   <pluginGroups/>
  139.   <servers/>
  140.   <mirrors/>
  141.   <proxies/>
  142.   <profiles/>
  143.   <activeProfiles/>
  144. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  145.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  146.   <localRepository/>
  147.   <interactiveMode/>
  148.   <offline/>
  149.   <pluginGroups/>
  150.   <servers/>
  151.   <mirrors/>
  152.   <proxies/>
  153.   <profiles/>
  154.   <activeProfiles/>
  155. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  156.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  157.   <localRepository/>
  158.   <interactiveMode/>
  159.   <offline/>
  160.   <pluginGroups/>
  161.   <servers/>
  162.   <mirrors/>
  163.   <proxies/>
  164.   <profiles/>
  165.   <activeProfiles/>
  166. </settings>          false<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  167.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  168.   <localRepository/>
  169.   <interactiveMode/>
  170.   <offline/>
  171.   <pluginGroups/>
  172.   <servers/>
  173.   <mirrors/>
  174.   <proxies/>
  175.   <profiles/>
  176.   <activeProfiles/>
  177. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  178.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  179.   <localRepository/>
  180.   <interactiveMode/>
  181.   <offline/>
  182.   <pluginGroups/>
  183.   <servers/>
  184.   <mirrors/>
  185.   <proxies/>
  186.   <profiles/>
  187.   <activeProfiles/>
  188. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  189.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  190.   <localRepository/>
  191.   <interactiveMode/>
  192.   <offline/>
  193.   <pluginGroups/>
  194.   <servers/>
  195.   <mirrors/>
  196.   <proxies/>
  197.   <profiles/>
  198.   <activeProfiles/>
  199. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  200.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  201.   <localRepository/>
  202.   <interactiveMode/>
  203.   <offline/>
  204.   <pluginGroups/>
  205.   <servers/>
  206.   <mirrors/>
  207.   <proxies/>
  208.   <profiles/>
  209.   <activeProfiles/>
  210. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  211.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  212.   <localRepository/>
  213.   <interactiveMode/>
  214.   <offline/>
  215.   <pluginGroups/>
  216.   <servers/>
  217.   <mirrors/>
  218.   <proxies/>
  219.   <profiles/>
  220.   <activeProfiles/>
  221. </settings>      false<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  222.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  223.   <localRepository/>
  224.   <interactiveMode/>
  225.   <offline/>
  226.   <pluginGroups/>
  227.   <servers/>
  228.   <mirrors/>
  229.   <proxies/>
  230.   <profiles/>
  231.   <activeProfiles/>
  232. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  233.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  234.   <localRepository/>
  235.   <interactiveMode/>
  236.   <offline/>
  237.   <pluginGroups/>
  238.   <servers/>
  239.   <mirrors/>
  240.   <proxies/>
  241.   <profiles/>
  242.   <activeProfiles/>
  243. </settings>    central<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  244.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  245.   <localRepository/>
  246.   <interactiveMode/>
  247.   <offline/>
  248.   <pluginGroups/>
  249.   <servers/>
  250.   <mirrors/>
  251.   <proxies/>
  252.   <profiles/>
  253.   <activeProfiles/>
  254. </settings>  maven<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  255.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  256.   <localRepository/>
  257.   <interactiveMode/>
  258.   <offline/>
  259.   <pluginGroups/>
  260.   <servers/>
  261.   <mirrors/>
  262.   <proxies/>
  263.   <profiles/>
  264.   <activeProfiles/>
  265. </settings>  https://artifactory.example.com/artifactory/maven<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  266.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  267.   <localRepository/>
  268.   <interactiveMode/>
  269.   <offline/>
  270.   <pluginGroups/>
  271.   <servers/>
  272.   <mirrors/>
  273.   <proxies/>
  274.   <profiles/>
  275.   <activeProfiles/>
  276. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  277.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  278.   <localRepository/>
  279.   <interactiveMode/>
  280.   <offline/>
  281.   <pluginGroups/>
  282.   <servers/>
  283.   <mirrors/>
  284.   <proxies/>
  285.   <profiles/>
  286.   <activeProfiles/>
  287. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  288.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  289.   <localRepository/>
  290.   <interactiveMode/>
  291.   <offline/>
  292.   <pluginGroups/>
  293.   <servers/>
  294.   <mirrors/>
  295.   <proxies/>
  296.   <profiles/>
  297.   <activeProfiles/>
  298. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  299.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  300.   <localRepository/>
  301.   <interactiveMode/>
  302.   <offline/>
  303.   <pluginGroups/>
  304.   <servers/>
  305.   <mirrors/>
  306.   <proxies/>
  307.   <profiles/>
  308.   <activeProfiles/>
  309. </settings>snapshots<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  310.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  311.   <localRepository/>
  312.   <interactiveMode/>
  313.   <offline/>
  314.   <pluginGroups/>
  315.   <servers/>
  316.   <mirrors/>
  317.   <proxies/>
  318.   <profiles/>
  319.   <activeProfiles/>
  320. </settings>  maven<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  321.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  322.   <localRepository/>
  323.   <interactiveMode/>
  324.   <offline/>
  325.   <pluginGroups/>
  326.   <servers/>
  327.   <mirrors/>
  328.   <proxies/>
  329.   <profiles/>
  330.   <activeProfiles/>
  331. </settings>  https://artifactory.example.com/artifactory/maven<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  332.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  333.   <localRepository/>
  334.   <interactiveMode/>
  335.   <offline/>
  336.   <pluginGroups/>
  337.   <servers/>
  338.   <mirrors/>
  339.   <proxies/>
  340.   <profiles/>
  341.   <activeProfiles/>
  342. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  343.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  344.   <localRepository/>
  345.   <interactiveMode/>
  346.   <offline/>
  347.   <pluginGroups/>
  348.   <servers/>
  349.   <mirrors/>
  350.   <proxies/>
  351.   <profiles/>
  352.   <activeProfiles/>
  353. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  354.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  355.   <localRepository/>
  356.   <interactiveMode/>
  357.   <offline/>
  358.   <pluginGroups/>
  359.   <servers/>
  360.   <mirrors/>
  361.   <proxies/>
  362.   <profiles/>
  363.   <activeProfiles/>
  364. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  365.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  366.   <localRepository/>
  367.   <interactiveMode/>
  368.   <offline/>
  369.   <pluginGroups/>
  370.   <servers/>
  371.   <mirrors/>
  372.   <proxies/>
  373.   <profiles/>
  374.   <activeProfiles/>
  375. </settings>    alimaven<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  376.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  377.   <localRepository/>
  378.   <interactiveMode/>
  379.   <offline/>
  380.   <pluginGroups/>
  381.   <servers/>
  382.   <mirrors/>
  383.   <proxies/>
  384.   <profiles/>
  385.   <activeProfiles/>
  386. </settings>  aliyun maven<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  387.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  388.   <localRepository/>
  389.   <interactiveMode/>
  390.   <offline/>
  391.   <pluginGroups/>
  392.   <servers/>
  393.   <mirrors/>
  394.   <proxies/>
  395.   <profiles/>
  396.   <activeProfiles/>
  397. </settings>  http://maven.aliyun.com/nexus/content/groups/public/<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  398.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  399.   <localRepository/>
  400.   <interactiveMode/>
  401.   <offline/>
  402.   <pluginGroups/>
  403.   <servers/>
  404.   <mirrors/>
  405.   <proxies/>
  406.   <profiles/>
  407.   <activeProfiles/>
  408. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  409.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  410.   <localRepository/>
  411.   <interactiveMode/>
  412.   <offline/>
  413.   <pluginGroups/>
  414.   <servers/>
  415.   <mirrors/>
  416.   <proxies/>
  417.   <profiles/>
  418.   <activeProfiles/>
  419. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  420.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  421.   <localRepository/>
  422.   <interactiveMode/>
  423.   <offline/>
  424.   <pluginGroups/>
  425.   <servers/>
  426.   <mirrors/>
  427.   <proxies/>
  428.   <profiles/>
  429.   <activeProfiles/>
  430. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  431.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  432.   <localRepository/>
  433.   <interactiveMode/>
  434.   <offline/>
  435.   <pluginGroups/>
  436.   <servers/>
  437.   <mirrors/>
  438.   <proxies/>
  439.   <profiles/>
  440.   <activeProfiles/>
  441. </settings>    false<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  442.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  443.   <localRepository/>
  444.   <interactiveMode/>
  445.   <offline/>
  446.   <pluginGroups/>
  447.   <servers/>
  448.   <mirrors/>
  449.   <proxies/>
  450.   <profiles/>
  451.   <activeProfiles/>
  452. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  453.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  454.   <localRepository/>
  455.   <interactiveMode/>
  456.   <offline/>
  457.   <pluginGroups/>
  458.   <servers/>
  459.   <mirrors/>
  460.   <proxies/>
  461.   <profiles/>
  462.   <activeProfiles/>
  463. </settings>    central<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  464.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  465.   <localRepository/>
  466.   <interactiveMode/>
  467.   <offline/>
  468.   <pluginGroups/>
  469.   <servers/>
  470.   <mirrors/>
  471.   <proxies/>
  472.   <profiles/>
  473.   <activeProfiles/>
  474. </settings>  maven<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  475.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  476.   <localRepository/>
  477.   <interactiveMode/>
  478.   <offline/>
  479.   <pluginGroups/>
  480.   <servers/>
  481.   <mirrors/>
  482.   <proxies/>
  483.   <profiles/>
  484.   <activeProfiles/>
  485. </settings>  https://artifactory.example.com/artifactory/maven<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  486.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  487.   <localRepository/>
  488.   <interactiveMode/>
  489.   <offline/>
  490.   <pluginGroups/>
  491.   <servers/>
  492.   <mirrors/>
  493.   <proxies/>
  494.   <profiles/>
  495.   <activeProfiles/>
  496. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  497.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  498.   <localRepository/>
  499.   <interactiveMode/>
  500.   <offline/>
  501.   <pluginGroups/>
  502.   <servers/>
  503.   <mirrors/>
  504.   <proxies/>
  505.   <profiles/>
  506.   <activeProfiles/>
  507. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  508.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  509.   <localRepository/>
  510.   <interactiveMode/>
  511.   <offline/>
  512.   <pluginGroups/>
  513.   <servers/>
  514.   <mirrors/>
  515.   <proxies/>
  516.   <profiles/>
  517.   <activeProfiles/>
  518. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  519.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  520.   <localRepository/>
  521.   <interactiveMode/>
  522.   <offline/>
  523.   <pluginGroups/>
  524.   <servers/>
  525.   <mirrors/>
  526.   <proxies/>
  527.   <profiles/>
  528.   <activeProfiles/>
  529. </settings>snapshots<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  530.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  531.   <localRepository/>
  532.   <interactiveMode/>
  533.   <offline/>
  534.   <pluginGroups/>
  535.   <servers/>
  536.   <mirrors/>
  537.   <proxies/>
  538.   <profiles/>
  539.   <activeProfiles/>
  540. </settings>  maven<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  541.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  542.   <localRepository/>
  543.   <interactiveMode/>
  544.   <offline/>
  545.   <pluginGroups/>
  546.   <servers/>
  547.   <mirrors/>
  548.   <proxies/>
  549.   <profiles/>
  550.   <activeProfiles/>
  551. </settings>  https://artifactory.example.com/artifactory/maven<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  552.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  553.   <localRepository/>
  554.   <interactiveMode/>
  555.   <offline/>
  556.   <pluginGroups/>
  557.   <servers/>
  558.   <mirrors/>
  559.   <proxies/>
  560.   <profiles/>
  561.   <activeProfiles/>
  562. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  563.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  564.   <localRepository/>
  565.   <interactiveMode/>
  566.   <offline/>
  567.   <pluginGroups/>
  568.   <servers/>
  569.   <mirrors/>
  570.   <proxies/>
  571.   <profiles/>
  572.   <activeProfiles/>
  573. </settings>    artifactory<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  574.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  575.   <localRepository/>
  576.   <interactiveMode/>
  577.   <offline/>
  578.   <pluginGroups/>
  579.   <servers/>
  580.   <mirrors/>
  581.   <proxies/>
  582.   <profiles/>
  583.   <activeProfiles/>
  584. </settings>          jdk-1.8<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  585.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  586.   <localRepository/>
  587.   <interactiveMode/>
  588.   <offline/>
  589.   <pluginGroups/>
  590.   <servers/>
  591.   <mirrors/>
  592.   <proxies/>
  593.   <profiles/>
  594.   <activeProfiles/>
  595. </settings>          true                1.8<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  596.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  597.   <localRepository/>
  598.   <interactiveMode/>
  599.   <offline/>
  600.   <pluginGroups/>
  601.   <servers/>
  602.   <mirrors/>
  603.   <proxies/>
  604.   <profiles/>
  605.   <activeProfiles/>
  606. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  607.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  608.   <localRepository/>
  609.   <interactiveMode/>
  610.   <offline/>
  611.   <pluginGroups/>
  612.   <servers/>
  613.   <mirrors/>
  614.   <proxies/>
  615.   <profiles/>
  616.   <activeProfiles/>
  617. </settings>    UTF-8                1.8                1.8                1.8<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  618.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  619.   <localRepository/>
  620.   <interactiveMode/>
  621.   <offline/>
  622.   <pluginGroups/>
  623.   <servers/>
  624.   <mirrors/>
  625.   <proxies/>
  626.   <profiles/>
  627.   <activeProfiles/>
  628. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  629.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  630.   <localRepository/>
  631.   <interactiveMode/>
  632.   <offline/>
  633.   <pluginGroups/>
  634.   <servers/>
  635.   <mirrors/>
  636.   <proxies/>
  637.   <profiles/>
  638.   <activeProfiles/>
  639. </settings>artifactory   
复制代码
Settings明细

简单值

顶级settings 元素的一半是简单值,表示一系列值,这些值描述了构建系统中一直处于激活(active full-time)的元素
  1. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  3.   <localRepository>${user.home}/.m2/repository</localRepository>
  4.   <interactiveMode>true</interactiveMode>
  5.   <offline>false</offline>
  6.   ...
  7. </settings>
复制代码
插件组(Plugin Groups)

此元素包含一个 pluginGroup 元素列表,每个元素都包含一个组ID。当用到某个插件并且命令行中没有提供该插件组件ID时,会搜索该列表。此列表自动包含org.apache.maven.plugins和org.codehaus.mojo。
  1. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  3.   ...
  4.   <pluginGroups>
  5.     <pluginGroup>org.eclipse.jetty</pluginGroup>
  6.   </pluginGroups>
  7.   ...
  8. </settings>
复制代码
例如,跟进上述给定的设置,Maven命令行可以使用截断的命令执行org.eclipse.jetty:jetty-Maven plugin:run:
  1. mvn jetty:run
复制代码
服务器(Servers)

由POM的repositionsdistributionManagement元素定义的,用于下载和发布的仓库。但是,某些设置(如 username 和password )不应与 pom.xml一起分发。此类信息应存在于 settings.xml中的生成服务器上。
  1. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  3.   ...
  4.   <servers>
  5.     <server>
  6.       <id>server001</id>
  7.       <username>my_login</username>
  8.       <password>my_password</password>
  9.       <privateKey>${user.home}/.ssh/id_dsa</privateKey>
  10.       <passphrase>some_passphrase</passphrase>
  11.       <filePermissions>664</filePermissions>
  12.       <directoryPermissions>775</directoryPermissions>
  13.       <configuration></configuration>
  14.     </server>
  15.   </servers>
  16.   ...
  17. </settings>
复制代码
注意:如果使用私钥登录服务器,请确保省略 元素。否则,该键将被忽略。
密码加密

2.1.0+中添加了一项新功能-服务器密码和passphrase加密。详情请查阅https://maven.apache.org/guides/mini/guide-encryption.html
镜像(Mirrors)
  1. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  3.   ...
  4.   <mirrors>
  5.     <mirror>
  6.       <id>planetmirror.com</id>
  7.       <name>PlanetMirror Australia</name>
  8.       <url>http://downloads.planetmirror.com/pub/maven2</url>
  9.       <mirrorOf>central</mirrorOf>
  10.     </mirror>
  11.   </mirrors>
  12.   ...
  13. </settings>
复制代码
有关镜像的更深入介绍,请阅读镜像设置指南
镜像设置指南

为仓库使用镜像

拥有仓库,你可以指定要从哪个位置下载某些工件,例如依赖项和maven插件。可以在项目内部声明仓库,这意味着,如果你有自己的自定义仓库,那些共享你项目的可以很容易地获得开箱即用的正确配置。但是,你可能希望在不更改项目文件的情况下为特定仓库使用备用镜像。
使用镜像的一些原因是:
可以简单的把mirror理解为一个拦截器,拦截maven对远程repository的相关请求,然后把请求里的remote repository地址,重定向到mirror里配置的地址,如下
未配置镜像前:

配置镜像之后:

要为给定仓库配置镜像,需在配置文件(${user.home}/.m2/settings.xml)中提供它,为新仓库指定自己的id和url,并指定mirrorOf设置,即被镜像的仓库ID。例如,默认情况下包含的Maven Central主仓库的ID为central,因此要使用不同的镜像实例,需要配置以下内容:
  1. <settings>
  2.   ...
  3.   <mirrors>
  4.     <mirror>
  5.       <id>other-mirror</id>
  6.       <name>Other Mirror Repository</name>
  7.       <url>https://other-mirror.repo.other-company.com/maven2</url>
  8.       <mirrorOf>central</mirrorOf>
  9.     </mirror>
  10.   </mirrors>
  11.   ...
  12. </settings>
复制代码
注意,对于给定的仓库,最多可以有一个镜像。换句话说,不能将单个仓库映射到一组定义相同值的镜像。Maven不会聚合镜像,而是简单地选择第一个匹配的镜像。如果要提供多个仓库的组合视图,请使用仓库管理器
settings.xml述符文档查阅https://maven.apache.org/ref/3.9.3/maven-settings/settings.html
:Maven的官方仓库位于https://repo.maven.apache.org/maven2由Sonatype公司托管,并通过CDN在全球范围内分发。
仓库Metadata中提供了已知镜像的列表。这些镜像可能没有相同的内容,我们不以任何方式支持它们。
使用单个仓库

可以通过让Maven镜像所有仓库请求来强制它使用单个仓库。仓库必须包含所有所需的工件,或者能够将请求代理到其他仓库。当使用具有代理外部请求的Maven 仓库管理器的内部公司仓库时,此设置最有用。
为此,请将 mirrorOf设置为*。
注意:此功能仅在Maven 2.0.5+中可用。
  1. <settings>
  2.   ...
  3.   <mirrors>
  4.     <mirror>
  5.       <id>internal-repository</id>
  6.       <name>Maven Repository Manager running on repo.mycompany.com</name>
  7.       <url>http://repo.mycompany.com/proxy</url>
  8.       <mirrorOf>*</mirrorOf>
  9.     </mirror>
  10.   </mirrors>
  11.   ...
  12. </settings>
复制代码
高级设置

单个镜像可以处理多个仓库。这通常与仓库管理器结合使用,后者可以方便地集中配置镜像背后的仓库列表。
语法:
注意不要在逗号分隔列表中的标识符或通配符周围包含额外的空格。例如,将设置为!repo1, *不会镜像任何内容,而!repo1,*将镜像除repo1之外的所有内容。
通配符在以逗号分隔的仓库标识符列表中的位置并不重要,因为通配符会推迟进一步处理,并且显式包含或排除会停止处理,从而否决任何通配符匹配(原文:The position of wildcards within a comma separated list of repository identifiers is not important as the wildcards defer to further processing and explicit includes or excludes stop the processing, overruling any wildcard match)。
当您使用高级语法并配置多个镜像时,声明顺序很重要。当Maven查找某个仓库的镜像时,它首先检查与仓库标识符完全匹配的镜像。如果没有找到直接匹配,Maven会根据上面的规则(如果有的话)选择第一个匹配的镜像声明。因此,可以通过更改settings.xml中定义的顺序来影响匹配顺序
示例:
  1. <settings>
  2.   ...
  3.   <mirrors>
  4.     <mirror>
  5.       <id>internal-repository</id>
  6.       <name>Maven Repository Manager running on repo.mycompany.com</name>
  7.       <url>http://repo.mycompany.com/proxy</url>
  8.       <mirrorOf>external:*,!foo</mirrorOf>
  9.     </mirror>
  10.     <mirror>
  11.       <id>foo-repository</id>
  12.       <name>Foo</name>
  13.       <url>http://repo.mycompany.com/foo</url>
  14.       <mirrorOf>foo</mirrorOf>
  15.     </mirror>
  16.   </mirrors>
  17.   ...
  18. </settings>
复制代码
创建自己的镜像

central仓库的大小正在稳步增加。为了节省带宽和你的时间,不允许镜像整个central仓库(如果这样做会被自动禁止)相反,建议设置一个仓库管理器 作为代理。
代理(Proxies)
  1. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  3.   ...
  4.   <proxies>
  5.     <proxy>
  6.       <id>myproxy</id>
  7.       <active>true</active>
  8.       <protocol>http</protocol>
  9.       <host>proxy.somewhere.com</host>
  10.       <port>8080</port>
  11.       <username>proxyuser</username>
  12.       <password>somepassword</password>
  13.       <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
  14.     </proxy>
  15.   </proxies>
  16.   ...
  17. </settings>
复制代码
Profiles

settings.xml中的profile 元素是 pom.xml profile 元素的“裁剪”版本。它由activation, repositories, pluginRepositories 和 properties 元素组成。 profile元素只包括这四个元素,因为它们关注的是整个构建系统(即settings.xml文件的作用),而不是单个项目对象模型设置。
如果一个settings.xml中的profile被激活,它的值会覆盖任何其它定义在pom.xml或profiles.xml中带有相同ID的profile。
Activation

Activations是配置文件的关键。与POM的profiles一样,profile的力量来自于它仅在特定情况下修改某些值的能力;这些情况是通过元素指定的。
  1.   ...            test              false        1.5<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  3.   <localRepository/>
  4.   <interactiveMode/>
  5.   <offline/>
  6.   <pluginGroups/>
  7.   <servers/>
  8.   <mirrors/>
  9.   <proxies/>
  10.   <profiles/>
  11.   <activeProfiles/>
  12. </settings>Windows XP          Windows          x86          5.1.2600<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  13.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  14.   <localRepository/>
  15.   <interactiveMode/>
  16.   <offline/>
  17.   <pluginGroups/>
  18.   <servers/>
  19.   <mirrors/>
  20.   <proxies/>
  21.   <profiles/>
  22.   <activeProfiles/>
  23. </settings>        mavenVersion          2.0.3<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  25.   <localRepository/>
  26.   <interactiveMode/>
  27.   <offline/>
  28.   <pluginGroups/>
  29.   <servers/>
  30.   <mirrors/>
  31.   <proxies/>
  32.   <profiles/>
  33.   <activeProfiles/>
  34. </settings>        ${basedir}/file2.properties          ${basedir}/file1.properties<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  35.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  36.   <localRepository/>
  37.   <interactiveMode/>
  38.   <offline/>
  39.   <pluginGroups/>
  40.   <servers/>
  41.   <mirrors/>
  42.   <proxies/>
  43.   <profiles/>
  44.   <activeProfiles/>
  45. </settings>  ...        ...
复制代码
当满足所有指定的条件时,将激活profile,但并非需要同时满足所有条件。
activation 元素并不是激活profile的唯一方式。 settings.xml文件的activeProfile 元素可能包含profile的id。它们也可以通过命令行,通过 -P 标志后的逗号分隔列表(例如 -P test)显式激活。
要查看哪个配置文件将在某个构建中激活,请使用maven-help-plugin。
  1. mvn help:active-profiles
复制代码
属性(Properties)

Maven properties是值占位符,类似于Ant中的properties。通过使用表示法 ${X},可以在POM中的任何位置访问它们的值,其中 X 是属性。它们有五种不同的形式,都可以从settings.xml文件中访问:
  1. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  3.   ...
  4.   <profiles>
  5.     <profile>
  6.       ...
  7.       <properties>
  8.         <user.install>${user.home}/our-project</user.install>
  9.       </properties>
  10.       ...
  11.     </profile>
  12.   </profiles>
  13.   ...
  14. </settings>
复制代码
如果profile被激活的话,可通过POM访问属性${user.install}
仓库(Repositories)

Repositories 是Maven用来填充构建系统的本地仓库的远程项目集合。Maven将其称为插件和依赖项的正是来自该本地仓库。不同的远程仓库可能包含不同的项目,profile激活的情况下,可以搜索它们以查找匹配的release或snapshot工件
  1.   ...            ...<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  3.   <localRepository/>
  4.   <interactiveMode/>
  5.   <offline/>
  6.   <pluginGroups/>
  7.   <servers/>
  8.   <mirrors/>
  9.   <proxies/>
  10.   <profiles/>
  11.   <activeProfiles/>
  12. </settings>      codehausSnapshots          Codehaus Snapshots<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  13.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  14.   <localRepository/>
  15.   <interactiveMode/>
  16.   <offline/>
  17.   <pluginGroups/>
  18.   <servers/>
  19.   <mirrors/>
  20.   <proxies/>
  21.   <profiles/>
  22.   <activeProfiles/>
  23. </settings>    false            always            warn<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  25.   <localRepository/>
  26.   <interactiveMode/>
  27.   <offline/>
  28.   <pluginGroups/>
  29.   <servers/>
  30.   <mirrors/>
  31.   <proxies/>
  32.   <profiles/>
  33.   <activeProfiles/>
  34. </settings>              true            never            fail<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  35.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  36.   <localRepository/>
  37.   <interactiveMode/>
  38.   <offline/>
  39.   <pluginGroups/>
  40.   <servers/>
  41.   <mirrors/>
  42.   <proxies/>
  43.   <profiles/>
  44.   <activeProfiles/>
  45. </settings>  http://snapshots.maven.codehaus.org/maven2          default<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  46.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  47.   <localRepository/>
  48.   <interactiveMode/>
  49.   <offline/>
  50.   <pluginGroups/>
  51.   <servers/>
  52.   <mirrors/>
  53.   <proxies/>
  54.   <profiles/>
  55.   <activeProfiles/>
  56. </settings><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  57.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  58.   <localRepository/>
  59.   <interactiveMode/>
  60.   <offline/>
  61.   <pluginGroups/>
  62.   <servers/>
  63.   <mirrors/>
  64.   <proxies/>
  65.   <profiles/>
  66.   <activeProfiles/>
  67. </settings>  myPluginRepo          My Plugins repo<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  68.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  69.   <localRepository/>
  70.   <interactiveMode/>
  71.   <offline/>
  72.   <pluginGroups/>
  73.   <servers/>
  74.   <mirrors/>
  75.   <proxies/>
  76.   <profiles/>
  77.   <activeProfiles/>
  78. </settings>    true<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  79.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  80.   <localRepository/>
  81.   <interactiveMode/>
  82.   <offline/>
  83.   <pluginGroups/>
  84.   <servers/>
  85.   <mirrors/>
  86.   <proxies/>
  87.   <profiles/>
  88.   <activeProfiles/>
  89. </settings>              false<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  90.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  91.   <localRepository/>
  92.   <interactiveMode/>
  93.   <offline/>
  94.   <pluginGroups/>
  95.   <servers/>
  96.   <mirrors/>
  97.   <proxies/>
  98.   <profiles/>
  99.   <activeProfiles/>
  100. </settings>  https://maven-central-eu....com/maven2/<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  101.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  102.   <localRepository/>
  103.   <interactiveMode/>
  104.   <offline/>
  105.   <pluginGroups/>
  106.   <servers/>
  107.   <mirrors/>
  108.   <proxies/>
  109.   <profiles/>
  110.   <activeProfiles/>
  111. </settings>  ...        ...
复制代码
插件仓库(Plugin Repositories)

仓库是两种主要类型的工件的所在地。第一种是用作其他工件的依赖项的工件。这些是位于中心的大多数工件。另一种类型的工件是插件。Maven插件本身就是一种特殊类型的工件。正因为如此,插件仓库可能会与其他仓库分离(尽管,我还没有听到这样做的令人信服的论据)。在任何情况下, pluginRepositories 元素块的结构都类似于 repositories 元素。 pluginRepository元素分别指定Maven可以在其中查找新插件的远程位置。
激活Profiles(Active Profiles)
  1. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  3.   ...
  4.   <activeProfiles>
  5.     <activeProfile>env-test</activeProfile>
  6.   </activeProfiles>
  7. </settings>
复制代码
settings.xml谜题的最后一块是activeProfiles 元素。它包含一系列activeProfiles 元素,每个元素的值都有一个 profile id。任何定义为activeProfile的profile id 都将处于活动状态,而与任何环境设置无关。如果没有找到匹配的profile,则什么也不会发生。例如,如果env-test为一个activeProfile,一个在具有相应id的pom.xml(或profile.xml)将处于活动状态。如果找不到这样的profile,则执行将照常进行。
参考链接

https://maven.apache.org/settings.html
https://maven.apache.org/ref/3.9.3/maven-settings/settings.html

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4