Maven-settings.xml
本地仓库存放路径
<localRepository>D:/mavenjar/.m2/repository</localRepository>
servers
<servers>
<server>
<id>id</id>
<username>用户名</username>
<password>密码</password>
</server>
</servers>
mirrors
<mirrors>
<mirror>
<id>id</id>
<name>my Nexus</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>aliyun</id>
<name>aliyun Maven</name>
<mirrorOf>*</mirrorOf>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
1> id:
是用来区别mirror的,所有的mirror不能有相同的id
2> mirrorOf:
用来表示该mirror是关联的哪一个仓库,其值为其关联仓库的id。当要同时关联多个仓库时,这多个仓库之间可以用逗号隔开;当要关联所有的仓库时,可以使用“*”表示;当要关联除某一个仓库以外的其他所有仓库时,可以表示为“*,!repositoryId”;当要关联不是localhost或用file请求的仓库时,可以表示为“external:*”。
profiles
用于指定一系列的profile。profile元素由activation、repositories、pluginRepositories和properties四个元素组成。当一个profile在settings.xml中是处于活动状态并且在pom.xml中定义了一个相同id的profile时,settings.xml中的profile会覆盖pom.xml中的profile。
activation
这是profile中最重要的元素。跟pom.xml中的profile一样,settings.xml中的profile也可以在特定环境下改变一些值,而这些环境是通过activation元素来指定的。
<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.6</jdk>
<os>
<name>Windows 7</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
<property>
<name>mavenVersion</name>
<value>2.0.3</value>
</property>
<file>
<exists>${basedir}/file2.properties</exists>
<missing>${basedir}/file1.properties</missing>
</file>
</activation>
...
</profile>
</profiles>
在上面这段代码中,当所有的约束条件都满足的时候就会激活这个profile。
jdk:表示当jdk的版本满足条件的时候激活,在这里是1.6。这里的版本还可以用一个范围来表示,如
<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满足;
os:表示当操作系统满足条件的时候激活。
property:property是键值对的形式,表示当Maven检测到了这样一个键值对的时候就激活该profile。
①下面的示例表示当存在属性hello的时候激活该profile。
<property>
<name>hello</name>
</property>
下面的示例表示当属性hello的值为world的时候激活该profile。
<property>
<name>hello</name>
<value>world</value>
</property>
这个时候如果要激活该profile的话,可以在调用Maven指令的时候加上参数hello并指定其值为world,如:mvn compile –Dhello=world
repositories
<repositories>
<repository>
<id>codehausSnapshots</id>
<name>Codehaus Snapshots</name>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>http://snapshots.maven.codehaus.org/maven2</url>
<layout>default</layout>
</repository>
</repositories>
releases、snapshots:这是对于工件的类型的限制。
enabled:表示这个仓库是否允许这种类型的工件
updatePolicy:表示多久尝试更新一次。可选值有always、daily、interval:minutes(表示每多久更新一次)和never。
checksumPolicy:当Maven在部署项目到仓库的时候会连同校验文件一起提交,checksumPolicy表示当这个校验文件缺失或不正确的时候该如何处理,可选项有ignore、fail和warn。
activeProfiles
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
参考:
https://blog.csdn.net/heima201907/article/details/105112679
https://blog.csdn.net/qq_23659871/article/details/85001539