Maven:解決IDEA無法下載源碼

問題

通過點(diǎn)擊進(jìn)IDEA反編譯的代碼文件處下載源代碼Sources:


image.png

IDEA提示報(bào)錯(cuò),無法下載源代碼:


image.png

解決辦法
一、下載全部依賴的源碼
mvn dependency:resolve是解決項(xiàng)目的所有依賴項(xiàng),它將打印出已解決依賴項(xiàng)的詳細(xì)信息。指定可選參數(shù)classifier=sources,將嘗試分析下載對(duì)應(yīng)的依賴的源代碼。打開Teminal,使用本地的Maven執(zhí)行,然后在下載就有了。

mvn dependency:resolve -Dclassifier=source

二、按需下載
先去確認(rèn) IDEA 的 File | Settings | Build, Execution, Deployment | Build Tools | Maven設(shè)置,Maven版本是3.8.4,配置文件也是3.8.4的,本地Maven倉庫也有設(shè)置。


image.png

再次嘗試下載源代碼,如果失敗,去查看本地的Maven倉庫有沒有一個(gè)后綴為sources.jar.lastUpdated的文件,這個(gè)文件是Maven嘗試下載源代碼但是失敗了的記錄文件。


image.png

使用notepad++打開該文件,根據(jù)里面的內(nèi)容,看來無法下載是和這個(gè)maven-default-http-blocker有很大的關(guān)系。
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Sun Nov 21 16:52:48 CST 2021
http\://0.0.0.0/.error=Could not transfer artifact org.slf4j\:slf4j-api\:jar\:sources\:1.7.21 from/to maven-default-http-blocker (http\://0.0.0.0/)\: Blocked mirror for repositories\: [nexus-aliyun (http\://maven.aliyun.com/nexus/content/groups/public, default, releases)]
@default-maven-default-http-blocker-http\://0.0.0.0/.lastUpdated=1637484768579

查看setting.xml文件,找到了以下相關(guān)的配置,上面說是這個(gè)maven-default-http-blocker阻礙了去阿里的鏡像庫查找依賴,注釋掉這個(gè)maven-default-http-blocker的鏡像,并且最好多找?guī)讉€(gè)鏡像加上去,可以防止一些鏡像沒有某個(gè)依賴導(dǎo)致報(bào)錯(cuò)。


image.png

保存后重啟IDEA。

常用鏡像

<!-- 阿里鏡像 -->
<mirror>
    <id>alimaven</id>
    <mirrorOf>central</mirrorOf>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>

<mirror>
    <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirrorOf>central</mirrorOf>
</mirror>

<mirror>
    <id>central</id>
    <name>Maven Repository Switchboard</name>
    <url>http://repo1.maven.org/maven2/</url>
    <mirrorOf>central</mirrorOf>
</mirror>

<mirror>
    <id>repo2</id>
    <mirrorOf>central</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://repo2.maven.org/maven2/</url>
</mirror>

<mirror>
    <id>ibiblio</id>
    <mirrorOf>central</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>

<mirror>
    <id>jboss-public-repository-group</id>
    <mirrorOf>central</mirrorOf>
    <name>JBoss Public Repository Group</name>
    <url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>

<mirror>
    <id>google-maven-central</id>
    <name>Google Maven Central</name>
    <url>https://maven-central.storage.googleapis.com
    </url>
    <mirrorOf>central</mirrorOf>
</mirror>

<!-- 中央倉庫在中國的鏡像 -->
<mirror>
    <id>maven.net.cn</id>
    <name>oneof the central mirrors in china</name>
    <url>http://maven.net.cn/content/groups/public/</url>
    <mirrorOf>central</mirrorOf>
</mirror>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容