出现了一个特殊的需求,有一个项目需要用它自己的nexus仓库进行maven构建,又不想另搞一套maven,所以构建的时候要指定配置文件,比如日常mvn操作是这样的
mvn clean install -DskipTests -e
为了指定配置文件,就需要改成这样的
mvn clean install -s /app/apache-maven-3.5.4/conf/new-settings.xml -DskipTests -e
所以关键就是new-settings.xml该怎么写,这也是最大的坑,这么写。主要是注意写mirrors这一块,否则mvn不认你的新仓库
<?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">
<localRepository>/app/apache-maven-3.5.4/repository_gateway</localRepository>
<pluginGroups></pluginGroups>
<proxies></proxies>
<mirrors>
<mirror>
<id>new-repo</id>
<mirrorOf>new-repo</mirrorOf>
<name>new-repo</name>
<url>http://new-nexus-url/new-repo</url>
</mirror>
</mirrors>
<servers>
<server>
<id>new-repo</id>
<username>xxxxx</username>
<password>xxxxxx</password>
</server>
</servers>
<profiles>
<profile>
<id>msmart</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
<repositories>
<repository>
<id>snapshots-repo</id>
<name>snapshots-repo</name>
<url>http://new-nexus-url/new-repo</url>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>your-own</activeProfile>
</activeProfiles>
</settings>