[toc]
maven global settings for closed source and open source projects
参考:https://maven.apache.org/settings.html
完整配置:settings.xml
settings.xml配置文件路径:
~/.m2/settings.xml
缺省本地仓库路径:
~/.m2/repository/
查看生效的settings.xml文件:
$ mvn -X clean | grep "settings"
[DEBUG] Imported: org.apache.maven.settings < plexus.core
[DEBUG] Reading global settings from /usr/local/bin/apache-maven-3.6.3/conf/settings.xml
[DEBUG] Reading user settings from /Users/gongpengjun/.m2/settings.xml
查看最终生效的配置内容:
$ mvn help:effective-settings
<settings>
<profiles>
<profile>
<id>privatemaven</id>
</profile>
<profile>
<id>alimaven</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>privatemaven</activeProfile>
<activeProfile>alimaven</activeProfile>
</activeProfiles>
</settings>
定义两个profile:
- 一个profile的id为 privatemaven
- 一个profile的id为 alimaven
activeProfiles激活两个profile:privatemaven和alimaven
<profile>
<id>privatemaven</id>
<repositories>
<repository>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
</pluginRepository>
</pluginRepositories>
</profile>
profile内可以定义多个普通仓库repositories和多个插件仓库pluginRepositories
普通仓库分为两个:一个release版仓库、一个snapshot版仓库
<repositories>
<repository>
<id>central</id>
<name>libs-release</name>
<url>http://artifactory.${PRIVATE_MAVEN_HOST}/artifactory/libs-release</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://artifactory.${PRIVATE_MAVEN_HOST}/artifactory/libs-snapshot</url>
</repository>
</repositories>
插件仓库分为两个:一个release版插件仓库、一个snapshot版插件仓库
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>plugins-release</name>
<url>http://artifactory.${PRIVATE_MAVEN_HOST}/artifactory/plugins-release</url>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://artifactory.${PRIVATE_MAVEN_HOST}/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
顶级字段servers配置私有仓库的用户名和密码,具体账号密码咨询私有maven仓库管理员
<settings>
<servers>
<server>
<username>${PRIVATE_MAVEN_USERNAME}</username>
<password>${PRIVATE_MAVEN_PASSWORD}</password>
<id>central</id>
</server>
<server>
<username>${PRIVATE_MAVEN_USERNAME}</username>
<password>${PRIVATE_MAVEN_PASSWORD}</password>
<id>snapshots</id>
</server>
</servers>
<profiles>
<profile>
<id>privatemaven</id>
</profile>
<profile>
<id>alimaven</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>privatemaven</activeProfile>
<activeProfile>alimaven</activeProfile>
</activeProfiles>
</settings>
参考:https://developer.aliyun.com/mvn/guide
<profile>
<id>alimaven</id>
<repositories>
<repository>
<id>public</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>