解讀maven配置阿里云鏡像問題
maven配置阿里云鏡像
打開maven配置文件,找到標簽,添加如下:
<mirrors> ? <mirror>? ? ? <id>alimaven</id>? ? ? <name>aliyun maven</name>? ? ? <url>http://maven.aliyun.com/nexus/content/groups/public/</url>? ? ? <mirrorOf>central</mirrorOf>? ? </mirror>? </mirrors>
設(shè)置全局的jdk,在配置文件配置如下:
<profile> ? ? ? <id>jdk18</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> ?? </profile> ?
設(shè)置局部的jdk,在項目的pom,xml文件中添加如下build元素
<build> ? ? ? <plugins> ? ? ? ? ? <plugin> ? ? ? ? ? ? ? <groupId>org.apache.maven.plugins</groupId> ? ? ? ? ? ? ? <artifactId>maven-compiler-plugin</artifactId> ? ? ? ? ? ? ? <configuration> ? ? ? ? ? ? ? ? ? <source>1.7</source> ? ? ? ? ? ? ? ? ? <target>1.7</target> ? ? ? ? ? ? ? </configuration> ? ? ? ? ? </plugin> ? ? ? </plugins> ? </build>
maven配置阿里云鏡像倉庫不生效
問題
在{MAVEN_HOME}/conf/settings.xml中添加鏡像配置:
? <mirrors> ? ? <mirror> ? ? ? ? <id>aliyunmaven</id> ? ? ? ? <mirrorOf>*</mirrorOf> ? ? ? ? <name>阿里云公共倉庫</name> ? ? ? ? <url>https://maven.aliyun.com/repository/public</url> ? ? </mirror> ? </mirrors>
但是項目更新時仍然會從http://repo.maven.apache.org/maven2下載依賴。
解決方法
在項目的pom.xml中添加如下配置
? <repositories> ? ? <repository> ? ? ? <id>central</id> ? ? ? <url>https://maven.aliyun.com/repository/public</url> ? ? </repository> ? </repositories> ? <pluginRepositories> ? ? <pluginRepository> ? ? ? <id>central</id> ? ? ? <url>https://maven.aliyun.com/repository/public</url> ? ? </pluginRepository> ? </pluginRepositories>
原因
項目的pom會繼承自super pom,在super pom中指定了從倉庫的地址:
<repositories> ? ? <repository> ? ? ? <id>central</id> ? ? ? <name>Central Repository</name> ? ? ? <url>http://repo.maven.apache.org/maven2</url> ? ? ? <layout>default</layout> ? ? ? <snapshots> ? ? ? ? <enabled>false</enabled> ? ? ? </snapshots> ? ? </repository> ? </repositories> ? ? <pluginRepositories> ? ? <pluginRepository> ? ? ? <id>central</id> ? ? ? <name>Central Repository</name> ? ? ? <url>http://repo.maven.apache.org/maven2</url> ? ? ? <layout>default</layout> ? ? ? <snapshots> ? ? ? ? <enabled>false</enabled> ? ? ? </snapshots> ? ? ? <releases> ? ? ? ? <updatePolicy>never</updatePolicy> ? ? ? </releases> ? ? </pluginRepository> ? </pluginRepositories>
因此需要在項目中覆蓋這一配置。
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Spring Boot Mysql 數(shù)據(jù)庫操作示例
本篇文章主要介紹了Spring Boot Mysql 數(shù)據(jù)庫操作示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02
Java中的轉(zhuǎn)換流InputStreamReader解讀
InputStreamReader是Java.io包中的一個類,用于將字節(jié)輸入流轉(zhuǎn)換為字符輸入流,它繼承自java.io.Reader類,提供了兩種構(gòu)造方法,可以使用默認或指定字符集創(chuàng)建實例,常用方法包括讀取字符、判斷是否準備好讀取數(shù)據(jù)和關(guān)閉流2024-09-09
springboot使用webservice發(fā)布和調(diào)用接口的實例詳解
本文介紹了如何在Springboot中使用webservice發(fā)布和調(diào)用接口,涵蓋了必要的依賴添加和代碼示例,文中提供了服務(wù)端和客戶端的實現(xiàn)方法,以及如何設(shè)置端口和服務(wù)地址,幫助讀者更好地理解和應(yīng)用Springboot結(jié)合webservice的技術(shù)2024-10-10
在Springboot中Mybatis與Mybatis-plus的區(qū)別詳解
MyBatis是一個優(yōu)秀的持久層框架,它對JDBC的操作數(shù)據(jù)庫的過程進行封裝,MyBatisPlus (簡稱 MP)是一個 MyBatis的增強工具,在 MyBatis 的基礎(chǔ)上只做增強不做改變,為簡化開發(fā)、提高效率而生,本文將給大家介紹了在Springboot中Mybatis與Mybatis-plus的區(qū)別2023-12-12
Spring?Boot的幾種統(tǒng)一處理方式梳理小結(jié)
這篇文章主要為大家介紹了Spring?Boot的幾種統(tǒng)一處理方式梳理小結(jié),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-05-05

