1、本地maven的settings.xml配置项
-
localRepository: 配置本地存储库的位置
-
interactiveMode: 是否与用户开启交互模式,默认为 true
-
offline: 离线模式,默认为 false
-
pluginGroups: 比如org.eclipse.jetty,默认有org.apache.maven.plugins and org.codehaus.mojo。
-
servers:配置私服的用户名和密码
-
mirrors: mirror相当于一个拦截器,它会拦截maven对remote repository的相关请求,把请求里的remote
repository地址,重定向到mirror里配置的地址。 -
proxies: 代理配置
-
profiles: 配置环境
-
activeProfiles: 配置默认激活的环境
2、本地maven的完整配置
<?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>本地仓库地址</localRepository>
<pluginGroups>
<pluginGroup>com.spotify</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>
</proxies>
<servers>
<!--maven私服地址搭建-->
<server>
<id>maven-public</id>
<username>私服的用户名</username>
<password>私服的密码</password>
</server>
<server>
<id>maven-releases</id>
<username>私服的用户名</username>
<password>私服的密码</password>
</server>
<server>
<id>maven-snapshots</id>
<username>私服的用户名</username>
<password>私服的密码</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<name>nexus</name>
<mirrorOf>local</mirrorOf>
<url>http://私服的ip:8081/repository/maven-public/</url>
</mirror>
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexusmaven</id>
<repositories>
<repository>
<id>nexus-maven</id>
<url>http://私服ip:8081/repository/maven-public</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-maven</id>
<url>http://私服ip:8081/repository/maven-public</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexusmaven</activeProfile>
</activeProfiles>
</settings>
3、idea项目中只需引入:
<!-- 代码库 ,配置后相当于从国内仓库拉取代码-->
<repositories>
<repository>
<id>maven-public</id>
<name>maven-public</name>
<url>http://私服ip:8081/repository/maven-public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
注意:
其中 id 要和你的仓库名称一致,url 就是私服的仓库地址,就是type 为 group 的那个,它组合了一个 proxy 类型的和两个 hosted 类型的仓库。设置 snapshots 的 enabled 为ture,表示允许下载 snapshots 版本的包。