通过点击进IDEA反编译的代码文件处下载源代码Sources:
IDEA提示报错,无法下载源代码:
一、下载全部依赖的源码
mvn dependency:resolve是解决项目的所有依赖项,它将打印出已解决依赖项的详细信息。指定可选参数classifier=sources,将尝试分析下载对应的依赖的源代码。打开Teminal,使用本地的Maven执行,然后在下载就有了。
powershell mvn dependency:resolve -Dclassifier=sources
二、按需下载
先去确认 IDEA 的 File | Settings | Build, Execution, Deployment | Build Tools | Maven设置,Maven版本是3.8.4,配置文件也是3.8.4的,本地Maven仓库也有设置。
再次尝试下载源代码,如果失败,去查看本地的Maven仓库有没有一个后缀为sources.jar.lastUpdated的文件,这个文件是Maven尝试下载源代码但是失败了的记录文件。
使用notepad++打开该文件,根据里面的内容,看来无法下载是和这个maven-default-http-blocker有很大的关系。
#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文件,找到了以下相关的配置,上面说是这个maven-default-http-blocker阻碍了去阿里的镜像库查找依赖,注释掉这个maven-default-http-blocker的镜像,并且最好多找几个镜像加上去,可以防止一些镜像没有某个依赖导致报错。
保存后重启IDEA
alimaven central aliyun maven http://maven.aliyun.com/nexus/content/repositories/central/ alimaven aliyun maven http://maven.aliyun.com/nexus/content/groups/public/ central central Maven Repository Switchboard http://repo1.maven.org/maven2/ central repo2 central Human Readable Name for this Mirror. http://repo2.maven.org/maven2/ ibiblio central Human Readable Name for this Mirror. http://mirrors.ibiblio.org/pub/mirrors/maven2/ jboss-public-repository-group central JBoss Public Repository Group http://repository.jboss.org/nexus/content/groups/public google-maven-central Google Maven Central https://maven-central.storage.googleapis.com central maven.net.cn oneof the central mirrors in china http://maven.net.cn/content/groups/public/ central



