Mavenのsetting.xmlファイル構造学習

また、常にされて、適切な場所がない場合は、学習の過程では、温かい歓迎は〜、おかげで私を修正するには

この記事では、著者の理解で随時更新されます。

Mavenの設定.xmlファイルの変換

<?xml version="1.0" encoding="UTF-8"?>
<!--
 | 这个是maven的配置文件,它可以在两种级别生效
 |
 |  1. 用户级别。settting.xml 文件可以给单个用户提供配置,
 |              用户级别配置文件通常位于${user.home}/.m2/settings.xml.
 |              注意:这个位置的配置可以用以下命令覆盖:
 |              -s /path/to/user/settings.xml
 | 
 |  2. 全局级别。setting.xml文件给在同一台机器上的全部用户和项目提供配置(假设使用同样的maven安装)
 |              全局级别配置文件通常位于${maven.conf}/settings.xml.
 |              注意:这个位置的配置可以用以下命令覆盖:
 |              -gs /path/to/global/settings.xml
 | 
 | 此文件中提供了大部分的默认配置,当没有指定setting配置文件时,使用该文件中的默认值。
 | 以使你能够在maven安装后快速开始使用。
 |
 |-->
 <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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | 这个路径指定了maven的本地仓库地址,默认为:${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <!-- interactiveMode
   | Maven是否需要和用户交互以获得输入。
   | 如果设置为false,当有参数需要用户指定时,maven将提供一个合理的默认值,或者基于其他设置。
   | 默认: true
  <interactiveMode>true</interactiveMode>
  -->
  <!-- offline
   | 决定maven是否需要在离线模式下构建(build)
   | 默认: false
  <offline>false</offline>
  -->
  <!-- pluginGroups
   | 默认情况下,当运行"mvn prefix:goal"时,maven只会在"org.apache.maven.plugins"和"org.codehaus.mojo"下搜索插件。
   | 当有自定义插件时,可以将包名定义在此,增加搜索范围
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | 指定包名使其能搜索相应插件
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>
  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | 指定网络代理
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>
  <!-- servers
   | 用户授权管理列表,当链接maven私服时,从这里读取授权信息。
   | 用id标记一个私服
   | 提示: username/password 或者 privateKey/passphrase 需要成对出现
   |-->
  <servers>
    <!-- server
     | 为指定的私服配置权限信息,用id这个属性确定一个唯一的系统
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->
    <!-- 也可以使用key的方式验证信息
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  <!-- mirrors
   | 这个列表用来配置私服的镜像站点,
   | 主要用来解决从中央仓库或者私服下载网速慢,服务器网络波动等问题。
   | 镜像需要有一个唯一的id,和profile.repository.id相照应。
   | mirrorOf标签用来指定是哪个仓库的镜像源,和profile.repository.id属性相对应。
   | 中央仓库的profile.repository.id默认值是central
   |-->
  <mirrors>
    <!-- mirror
     | id 值必须是唯一的
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
  </mirrors>
  <!-- profiles
   | 根据环境参数来调整构建配置的列表。settings.xml中的profile元素是pom.xml中profile元素的裁剪版本。
   | 它包含了id,activation, repositories, pluginRepositories和 properties元素。
   | 这里的profile元素只包含这五个子元素是因为这里只关心构建系统这个整体(这正是settings.xml文件的角色定位),而非单独的项目对象模型设置。
   | 如果一个settings中的profile被激活,它的值会覆盖任何其它定义在POM中或者profile.xml中的带有相同id的profile。
   |
   | 举个例子,当你在不同的JDK版本下有不同的需求时,你可以设置不同的profile
   |-->
  <profiles>
    <profile>
      <id>jdk-1.4</id>
      <activation>
        <jdk>1.4</jdk>
      </activation>
      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>
      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>
      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
  </profiles>
  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

Mavenのsetting.xmlファイル内部のラベルの指示との関係

リポジトリ、ミラー、サーバ間の関係におけるMavenの設定

  • ローカルリポジトリが存在しない場合、使用中のリポジトリは、時間の依存性を見つけるために、Mavenのあなたは、マルチ倉庫の数を指定することができます(依存スナップショットを引っ張ることができるかどうかなど)を使用する方法を一意に遠隔倉庫識別、アドレス、名前、、、を含む、リモートリポジトリを指定します、リモートリポジトリからそれを見下ろして、ダウンロードした見つけ、すべて見てフィニッシュが見つからない見つけることができません
  • リポジトリIDでのリポジトリがmirrorOfであれば、mirrorOfによって指定されたウェアハウス・エージェント内のミラーは、リモートリポジトリへのプロキシ要求を開始する(直接指定することができ、あなたも指定するために、いくつかのマッチング文字を使用することができます)倉庫の物質であることが指定されましたマッチした、この要求を送信するために、その後のMavenリポジトリは、他の薬剤のミラーにURLを支配しました
  • 与えられた身元認証情報のサーバ、最もプライベートサーバは、ユーザ名とパスワードを持っているので、それ以外の場合は危険なので、ここで指定したユーザー名とパスワードを見て、リポジトリID内のサーバーへのidマッチがリポジトリにアクセスするためのユーザー名とパスワードを見つけるために

付録

一般的に、ミラーに使用達人

  • アリクラウドミラー元
<mirror>
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirrorOf>central</mirrorOf>        
</mirror>

引用文

リポジトリ、ミラー、サーバ間の関係におけるMavenの設定

おすすめ

転載: www.cnblogs.com/virde/p/maven_setting_study.html