<?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>D:\maven\repository</localRepository> <servers> <!-- 1、這里要配置配置上傳用戶及倉庫信息 --> <server> <id>nexus</id> <username>admin</username> <password>xxxx</password> </server> </servers> <!-- 2、添加maven倉庫鏡像 --> <mirrors> <mirror> <id>central-proxy</id> <mirrorOf>central</mirrorOf> <url>https://xxxx</url> </mirror> </mirrors> <!-- 3、這種方式配置后所有本地使用該配置的maven項目的pom文件都無需配置私服下載相關配置。 --> <profiles> <profile> <id>mycof</id> <repositories> <repository> <id>nexus</id> <name>my's nexus</name> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> <url>http://xxx/groups/public</url> </repository> </repositories> <pluginRepositories> <!--插件庫地址--> <pluginRepository> <id>nexus</id> <url>http://xxxx/groups/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <!-/4、激活profile--> <activeProfiles> <activeProfile>mycof</activeProfile> </activeProfiles> </settings>
當構建一個Maven項目時,首先檢查pom.xml文件以確定依賴包的下載位置,執行順序如下:
1、從本地資源庫中查找並獲得依賴包,如果沒有,執行第2步。
2、如果在pom.xml中定義了自定義的遠程倉庫,那么也會在這里的倉庫中進行查找並獲得依賴包,如果沒有,執行第3步。
3、從Maven默認中央倉庫中查找並獲得依賴包(https://repo1.maven.org/maven2/),如果都沒有找到,那么Maven就會拋出異常。
默認中央倉庫的地址:
1、http://repo1.maven.org/maven2/
默認的中央倉庫id為【central】, setting中<mirrorOf>central</mirrorOf>表示不再從默認中央倉庫中獲取jar,一般為公司私服地址。
2、profiles 設置表示:設置一個指定的存儲庫地址。下載順序為: 本地庫->profiles地址->中央倉庫【有mirrorOf則從mirror地址下載,不會再查詢默認的中央倉庫】
配置server:
是向私服上傳jar時使用,id 一 一對應,項目中需要在pom.xml中配置如下
<distributionManagement> <repository> <id>nexus</id> <name>releases</name> <url>http://xxx/content/repositories/releases</url> </repository> <snapshotRepository> <id>nexus</id> <name>snapshots</name> <url>http://xxx/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement>