解讀maven配置阿里云鏡像問題
maven配置阿里云鏡像
打開maven配置文件,找到標(biāo)簽,添加如下:
<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,在項(xiàng)目的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>
但是項(xiàng)目更新時仍然會從http://repo.maven.apache.org/maven2下載依賴。
解決方法
在項(xiàng)目的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>
原因
項(xiàng)目的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>
因此需要在項(xiàng)目中覆蓋這一配置。
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
關(guān)于SpringBoot微服務(wù)發(fā)布與部署的三種方式
SpringBoot 框架只提供了一套基于可執(zhí)行 jar 包(executable jar)格式的標(biāo)準(zhǔn)發(fā)布形式,但并沒有對部署做過多的界定,而且為了簡化可執(zhí)行 jar 包的生成,SpringBoot 提供了相應(yīng)的 Maven 項(xiàng)目插件,需要的朋友可以參考下2023-05-05Java String、StringBuffer與StringBuilder的區(qū)別
本文主要介紹Java String、StringBuffer與StringBuilder的區(qū)別的資料,這里整理了相關(guān)資料及詳細(xì)說明其作用和利弊點(diǎn),有需要的小伙伴可以參考下2016-09-09Java終止循環(huán)體的具體實(shí)現(xiàn)
這篇文章主要介紹了Java終止循環(huán)體的具體實(shí)現(xiàn),需要的朋友可以參考下2014-02-02