IntelliJ环境下Maven下载log4j-core等依赖失败问题咨询
问题现象
我使用IntelliJ IDEA 2021.2.2(旗舰版)搭配Maven 3.6.3开发Spring Boot库项目,项目pom.xml配置如下:
<parent> <groupId>org.pickme</groupId> <artifactId>spring-boot-etcd-starter</artifactId> <version>1.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <artifactId>etcd-client</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.14.1</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.14.1</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-yaml</artifactId> <version>2.13.0</version> </dependency> </dependencies> <properties> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> <jetcd.version>0.5.8</jetcd.version> </properties>
执行mvn clean install命令时出现依赖下载失败问题,log4j-api可正常解析,但log4j-core和log4j-slf4j-impl无法正常下载,报错信息如下:
Could not transfer artifact org.apache.logging.log4j:log4j-core:pom:2.14.1 from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/apache/logging/log4j/log4j-core/2.14.1/log4j-core-2.14.1.pom
补充说明:已核对IntelliJ IDEA设置中的Maven仓库配置,所有仓库链接均可通过浏览器正常访问。idea.log中存在如下警告:
2021-11-04 16:01:32,805 [3353406] INFO - indexing.UnindexedFilesUpdater - Scanning of spring-boot-etcd-starter uses 7 scanning threads 2021-11-04 16:01:32,836 [3353437] WARN - arketplace.MarketplaceRequests - Can not get compatible updates from Marketplace: Remote host terminated the handshake 2021-11-04 16:01:33,017 [3353618] WARN - arketplace.MarketplaceRequests - Can not get JetBrains plugins' IDs from Marketplace: Remote host terminated the handshake 2021-11-04 16:01:33,026 [3353627] WARN - arketplace.MarketplaceRequests - Can not get JetBrains plugins' IDs from Marketplace: Remote host terminated the handshake 2021-11-04 16:01:33,036 [3353637] WARN - arketplace.MarketplaceRequests - Can not get JetBrains plugins' IDs from Marketplace: Remote host terminated the handshake 2021-11-04 16:01:33,127 [3353728] WARN - arketplace.MarketplaceRequests - Can not get JetBrains plugins' IDs from Marketplace: Remote host terminated the handshake 2021-11-04 16:01:33,176 [3353777] WARN - arketplace.MarketplaceRequests - Can not get JetBrains plugins' IDs from Marketplace: Remote host terminated the handshake
堆栈跟踪中存在如下异常:
Suppressed: java.net.SocketException: Broken pipe (Write failed) Caused by: java.io.EOFException: SSL peer shut down incorrectly
解决方案
该问题是JVM SSL栈与Maven中央仓库的TLS版本兼容性问题导致,浏览器使用系统SSL栈可正常访问不代表Maven使用的JDK SSL栈可正常建立连接,可按以下步骤排查解决:
- 清理本地Maven仓库缓存:删除本地仓库路径下
org/apache/logging/log4j/log4j-core/2.14.1、org/apache/logging/log4j/log4j-slf4j-impl两个目录内所有后缀为.lastUpdated的文件,避免Maven缓存下载失败状态跳过重试。 - 强制Maven使用TLS 1.2协议连接仓库:在Maven全局
settings.xml的profiles节点下新增如下配置:
<profile> <id>tls12-enable</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <maven.wagon.http.ssl.protocols>TLSv1.2</maven.wagon.http.ssl.protocols> </properties> </profile>
- 配置IDEA Maven运行参数:打开IDEA设置>构建、执行、部署>构建工具>Maven>运行程序,在VM选项栏添加参数
-Dhttps.protocols=TLSv1.2。 - 排查网络拦截:检查是否开启了网络代理、企业内网防火墙是否拦截大文件HTTPS传输,log4j-core体积远大于log4j-api,容易触发流量拦截规则,可临时切换公共网络重试。
- 手动导入依赖:如果以上方案均无效,可手动下载对应版本的pom、jar文件,放到本地Maven仓库对应的目录下,再执行install命令即可。
内容的提问来源于stack exchange,提问作者mster3313
相关产品推荐
相关产品推荐

