当前位置:   article > 正文

Maven的settings.xml文件结构之Servers,Mirror和Repository_maven settings server

maven settings server

一个Setting.xml模板解析
maven的配置文件settings.xml中,有Servers节点,Mirror节点和Repository节点,一个典型的settings.xml配置如下

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <!-- 本地仓库的路径。默认值为${user.home}/.m2/repository。 -->
    <localRepository>E:/java/apache-maven-3.3.9/repository</localRepository>
    <!--Maven是否需要和用户交互以获得输入。如果Maven需要和用户交互以获得输入,则设置成true,反之则应为false。默认为true。-->
    <!--<interactiveMode>true</interactiveMode>-->
    <!--表示是否离线,默认是false。这个属性表示在Maven进行项目编译和部署等操作时是否允许Maven进行联网来下载所需要的信息。  -->
    <!-- <offline>false</offline>
  -->
    <!--当插件的组织Id(groupId)没有显式提供时,供搜寻插件组织Id(groupId)的列表。该元素包含一个pluginGroup元素列表,每个子元素包含了一个组织Id(groupId)。当我们使用某个插件,并且没有在命令行为其提供组织Id(groupId)的时候,Maven就会使用该列表。默认情况下该列表包含了org.apache.maven.plugins和org.codehaus.mojo -->
    <pluginGroups>
        <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
    </pluginGroups>
    <!--其下面可以定义一系列的proxy子元素,表示Maven在进行联网时需要使用到的代理。当设置了多个代理的时候第一个标记active为true的代理将会被使用。 -->
    <proxies>
        <!--代理元素包含配置代理时需要的信息-->
        <proxy>
            <!-- 代理的唯一定义符,用来区分不同的代理元素。-->
            <id>optional</id>
            <!--该代理是否是激活的那个。true则激活代理。当我们声明了一组代理,而某个时候只需要激活一个代理的时候,该元素就可以派上用处。 -->
            <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>
        <!--服务器元素包含配置服务器时需要的信息
  发布的服务器,发布的位置在POM中配置,以ID为关联,有很多公用的信息需要配置在POM文件里,最佳实践是定义一个公司级别的root pom - 
	-->
        <server>
            <!--这是server的id(注意不是用户登陆的id),该id与distributionManagement中repository元素的id相匹配。-->
            <id>frame-releases</id>
            <!--鉴权用户名。鉴权用户名和鉴权密码表示服务器认证所需要的登录名和密码。 -->
            <username>admin</username>
            <!--鉴权用户名。鉴权用户名和鉴权密码表示服务器认证所需要的登录名和密码。 -->
            <password>admin123</password>
        </server>
        <server>
            <id>siteServer</id>
            <!--鉴权时使用的私钥位置。和前两个元素类似,私钥位置和私钥密码指定了一个私钥的路径(默认是${user.home}/.ssh/id_dsa)以及如果需要的话,一个密语。将来passphrase和password元素可能会被提取到外部,但目前它们必须在settings.xml文件以纯文本的形式声明。 -->
            <privateKey>/path/to/private/key</privateKey>
            <!--鉴权时使用的私钥密码。-->
            <passphrase>optional; leave empty if not used.</passphrase>
            <!--文件被创建时的权限。如果在部署的时候会创建一个仓库文件或者目录,这时候就可以使用权限(permission)。这两个元素合法的值是一个三位数字,其对应了unix文件系统的权限,如664,或者775。 -->
            <filePermissions>664</filePermissions>
            <!--目录被创建时的权限。 -->
            <directoryPermissions>775</directoryPermissions>
        </server>
    </servers>
    <!--用于定义一系列的远程仓库的镜像。我们可以在pom中定义一个下载工件的时候所使用的远程仓库。但是有时候这个远程仓库会比较忙,所以这个时候人们就想着给它创建镜像以缓解远程仓库的压力,也就是说会把对远程仓库的请求转换到对其镜像地址的请求。每个远程仓库都会有一个id,这样我们就可以创建自己的mirror来关联到该仓库,那么以后需要从远程仓库下载工件的时候Maven就可以从我们定义好的mirror站点来下载,这可以很好的缓解我们远程仓库的压力。在我们定义的mirror中每个远程仓库都只能有一个mirror与它关联,也就是说你不能同时配置多个mirror的mirrorOf指向同一个repositoryId。-->
    <mirrors>
        <mirror>
            <!--该镜像的唯一标识符。id用来区分不同的mirror元素。 -->
            <id>mirrorId</id>
            <!-- 用来表示该mirror是关联的哪一个仓库,其值为其关联仓库的id。当要同时关联多个仓库时,这多个仓库之间可以用逗号隔开;当要关联所有的仓库时,可以使用“*”表示;当要关联除某一个仓库以外的其他所有仓库时,可以表示为“*,!repositoryId”;当要关联不是localhost或用file请求的仓库时,可以表示为“external:*”。-->
            <mirrorOf>repositoryId</mirrorOf>
            <!--镜像名称 -->
            <name>Human Readable Name for this Mirror.</name>
            <!--该镜像的URL。构建系统会优先考虑使用该URL,而非使用默认的服务器URL。 -->
            <url>http://196.160.1.211:8081/nexus/content/groups/public/</url>
        </mirror>
    </mirrors>
    <!--用于指定一系列的profile。profile元素由activation、repositories、pluginRepositories和properties四个元素组成。当一个profile在settings.xml中是处于活动状态并且在pom.xml中定义了一个相同id的profile时,settings.xml中的profile会覆盖pom.xml中的profile。 -->
    <profiles>
        <!--根据环境参数来调整的构件的配置-->
        <profile>
            <!--该配置的唯一标识符。 -->
            <id>jdk-1.4</id>
            <!--当所有的约束条件都满足的时候就会激活这个profile。-->
            <activation>
                <!--当其值为true的时候表示如果没有其他的profile处于激活状态的时候,该profile将自动被激活。-->
                <activeByDefault>false</activeByDefault>
                <!--当匹配的jdk被检测到,profile被激活。例如,1.4激活JDK1.4,1.4.0_2,而!1.4激活所有版本不是以1.4开头的JDK。
 这里的版本还可以用一个范围来表示,如
<jdk>[1.4,1.7)</jdk>表示1.4、1.5和1.6满足;
<jdk>[1.4,1.7]</jdk>表示1.4、1.5、1.6和1.7满足;-->
                <jdk>1.5</jdk>
                <!--表示当操作系统满足条件的时候激活。-->
                <os>
                    <!--激活profile的操作系统的名字 -->
                    <name>Windows XP</name>
                    <!--激活profile的操作系统所属家族(如 'windows')  -->
                    <family>Windows</family>
                    <!--激活profile的操作系统体系结构  -->
                    <arch>x86</arch>
                    <!--激活profile的操作系统版本-->
                    <version>5.1.2600</version>
                </os>
                <!--property是键值对的形式,表示当Maven检测到了这样一个键值对的时候就激活该profile。如果值字段是空的,那么存在属性名称字段就会激活profile,否则按区分大小写方式匹配属性值字段-->
                <property>
                    <!--这个时候如果要激活该profile的话,可以在调用Maven指令的时候加上参数mavenVersion并指定其值为>2.0.3,如:mvn compile –DmavenVersion=>2.0.3-->
                    <name>mavenVersion</name>
                    <!--激活profile的属性的值 -->
                    <value>2.0.3</value>
                </property>
                <!--表示当文件存在或不存在的时候激活,exists表示存在,missing表示不存在。如下面的例子表示当文件hello/world不存在的时候激活该profile。-->
                <file>
                    <!--如果指定的文件存在,则激活profile。 -->
                    <exists>${basedir}/file2.properties</exists>
                    <!--如果指定的文件不存在,则激活profile。-->
                    <missing>${basedir}/file1.properties</missing>
                </file>
            </activation>
            <!--用于定义远程仓库的,当该profile是激活状态的时候,这里面定义的远程仓库将作为当前pom的远程仓库。 -->
            <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>
        <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>
        <profile>
            <id>nexusProfile</id>
            <!--远程仓库列表,它是Maven用来填充构建系统本地仓库所使用的一组远程项目。 -->
            <repositories>
                <!--包含需要连接到远程仓库的信息 -->
                <repository>
                    <!--远程仓库唯一标识-->
                    <id>nexusProfile</id>
                    <!--远程仓库名称 -->
                    <name>nexus repository</name>
                    <!--用于定位和排序构件的仓库布局类型-可以是default(默认)或者legacy(遗留)。Maven 2为其仓库提供了一个默认的布局;然而,Maven 1.x有一种不同的布局。我们可以使用该元素指定布局是default(默认)还是legacy(遗留)。 -->
                    <layout>default</layout>
                    <!--远程仓库URL,按protocol://hostname/path形式
		  -->
                    <url>http://196.160.1.211:8081/nexus/content/groups/public/</url>
                    <!--如何处理远程仓库里发布版本的下载-->
                    <releases>
                        <!--true或者false表示该仓库是否为下载某种类型构件(发布版,快照版)开启。  -->
                        <enabled>true</enabled>
                        <!--该元素指定更新发生的频率。Maven会比较本地POM和远程POM的时间戳。这里的选项是:always(一直),daily(默认,每日),interval:X(这里X是以分钟为单位的时间间隔),或者never(从不)。 -->
                        <updatePolicy>always</updatePolicy>
                        <!--当Maven验证构件校验文件失败时该怎么做-ignore(忽略),fail(失败),或者warn(警告)。-->
                        <checksumPolicy>warn</checksumPolicy>
                    </releases>
                    <!--如何处理远程仓库里快照版本的下载。有了releases和snapshots这两组配置,POM就可以在每个单独的仓库中,为每种类型的构件采取不同的策略。例如,可能有人会决定只为开发目的开启对快照版本下载的支持。参见repositories/repository/releases元素-->
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
        </profile>
        <profile>
            <id>centralProfile</id>
            <repositories>
                <repository>
                    <id>central</id>
                    <name>Central Repository</name>
                    <!-- 虚拟的URL形式,指向镜像的URL,因为所有的镜像都是用的是nexus,这里的central实际上指向的是http://repos.d.xxx.com/nexus/content/groups/public -->
                    <url>https://repo.maven.apache.org/maven2</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
        </profile>
    </profiles>
    <!--手动激活profiles的列表,按照profile被应用的顺序定义activeProfile。 该元素包含了一组activeProfile元素,每个activeProfile都含有一个profile id。任何在activeProfile中定义的profile id,不论环境设置如何,其对应的
        profile都会被激活。如果没有匹配的profile,则什么都不会发生。例如,env-test是一个activeProfile,则在pom.xml(或者profile.xml)中对应id的profile会被激活。如果运行过程中找不到这样一个profile,Maven则会像往常一样运行。 -->
    <activeProfile>nexusProfile</activeProfile>
    <activeProfile>centralProfile</activeProfile>
</settings>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/87473
推荐阅读
相关标签
  

闽ICP备14008679号