maven配置多個倉庫的實現(xiàn)
說明
maven的中央倉庫很強大,絕大多數(shù)的jar都收錄了。但也有未被收錄的。遇到未收錄的jar時,就會編譯報錯。
除了maven官方提供的倉庫之外,也有很多的倉庫。盡可能的將可信的倉庫(嗯,可信的倉庫!)添加幾個,彌補maven官方倉庫的不足。
多倉庫配置方式一:全局多倉庫設置
全局多倉庫設置,是通過修改maven的setting文件實現(xiàn)的。
設置思路:在setting文件中添加多個profile(也可以在一個profile中包含很多個倉庫),并激活(即使是只有一個可用的profile,也需要激活)。
修改maven的setting文件,設置兩個倉庫(以此類推,可以添加多個):
? <profiles> ? ? <profile> ? ? ? ? <!-- id必須唯一 --> ? ? ? ? <id>myRepository1</id> ? ? ? ? <repositories> ? ? ? ? ? ? <repository> ? ? ? ? ? ? ? ? <!-- id必須唯一 --> ? ? ? ? ? ? ? ? <id>myRepository1_1</id> ? ? ? ? ? ? ? ? <!-- 倉庫的url地址 --> ? ? ? ? ? ? ? ? <url>http://maven.aliyun.com/nexus/content/groups/public/</url> ? ? ? ? ? ? ? ? <releases> ? ? ? ? ? ? ? ? ? ? <enabled>true</enabled> ? ? ? ? ? ? ? ? </releases> ? ? ? ? ? ? ? ? <snapshots> ? ? ? ? ? ? ? ? ? ? <enabled>true</enabled> ? ? ? ? ? ? ? ? ? ? <updatePolicy>always</updatePolicy> ? ? ? ? ? ? ? ? </snapshots> ? ? ? ? ? ? </repository> ? ? ? ? </repositories> ? ? </profile> ? ? <profile> ? ? ? ? <!-- id必須唯一 --> ? ? ? ? <id>myRepository2</id> ? ? ? ? <repositories> ? ? ? ? ? ? <repository> ? ? ? ? ? ? ? ? <!-- id必須唯一 --> ? ? ? ? ? ? ? ? <id>myRepository2_1</id> ? ? ? ? ? ? ? ? <!-- 倉庫的url地址 --> ? ? ? ? ? ? ? ? <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url> ? ? ? ? ? ? ? ? <releases> ? ? ? ? ? ? ? ? ? ? <enabled>true</enabled> ? ? ? ? ? ? ? ? </releases> ? ? ? ? ? ? ? ? <snapshots> ? ? ? ? ? ? ? ? ? ? <enabled>true</enabled> ? ? ? ? ? ? ? ? ? ? <updatePolicy>always</updatePolicy> ? ? ? ? ? ? ? ? </snapshots> ? ? ? ? ? ? </repository> ? ? ? ? </repositories> ? ? </profile> ? </profiles> ? <activeProfiles> ? ? <!-- 激活myRepository1 --> ? ? <activeProfile>myRepository1</activeProfile> ? ? <!-- 激活myRepository2 --> ? ? <activeProfile>myRepository2</activeProfile> ? </activeProfiles>
多倉庫配置方式二:在項目中添加多個倉庫
在項目中添加多個倉庫,是通過修改項目中的pom文件實現(xiàn)的。
思路:在項目中pom文件的repositories節(jié)點(如果沒有手動添加)下添加多個repository節(jié)點,每個repository節(jié)點是一個倉庫。
修改項目中pom文件,設置兩個倉庫(以此類推,可以添加多個):
? ? <repositories> ? ? ? ? <repository> ? ? ? ? ? ? <!-- id必須唯一 --> ? ? ? ? ? ? <id>jboss-repository</id> ? ? ? ? ? ? <!-- 見名知意即可 --> ? ? ? ? ? ? <name>jboss repository</name> ? ? ? ? ? ? <!-- 倉庫的url地址 --> ? ? ? ? ? ? <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url> ? ? ? ? </repository> ? ? ? ? <repository> ? ? ? ? ? ? <!-- id必須唯一 --> ? ? ? ? ? ? <id>aliyun-repository</id> ? ? ? ? ? ? <!-- 見名知意即可 --> ? ? ? ? ? ? <name>aliyun repository</name> ? ? ? ? ? ? <!-- 倉庫的url地址 --> ? ? ? ? ? ? <url>http://maven.aliyun.com/nexus/content/groups/public/</url> ? ? ? ? </repository> ? ? </repositories>
注:以上兩種方式的id值均不可以為“central”。
到此這篇關于maven配置多個倉庫的實現(xiàn)的文章就介紹到這了,更多相關maven 多個倉庫內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
JVM?運行時數(shù)據(jù)區(qū)與JMM?內存模型
這篇文章主要介紹了JVM?運行時數(shù)據(jù)區(qū)與JMM?內存模型,文章圍繞主題展開詳細的內容介紹,具有一定的參考價值。需要的朋友可以參考一下2022-07-07@ConfigurationProperties遇到的坑及解決
這篇文章主要介紹了解決@ConfigurationProperties遇到的坑,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-07-07Spring Boot如何使用Undertow代替Tomcat
這篇文章主要介紹了Spring Boot如何使用Undertow代替Tomcat,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-09-09解決Maven的pom.xml中設置repository不起作用問題
這篇文章主要介紹了解決Maven的pom.xml中設置repository不起作用問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03