使用 allowInsecureProtocol 属性解决 gradle 的仓库地址不安全警告

本文介绍如何通过设置allowInsecureProtocol属性来解决Gradle在使用不安全仓库时产生的警告。此方法适用于那些希望继续使用HTTP而非HTTPS协议的仓库而又不想看到警告信息的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用 allowInsecureProtocol 属性解决 gradle 的仓库地址不安全警告

在 IDEA 的 Terminal 中使用命令 gradlew --warning-mode all 可以打印出当前 gradle 存在的所有警告信息


正文

如果有报以下警告:

Using insecure protocols with repositories, without explicit opt-in, has been deprecated. This is scheduled to be removed in Gradle 7.0. Switch Maven repository 'm
aven(http://maven.aliyun.com/nexus/content/groups/public/)' to a secure protocol (like HTTPS) or allow insecure protocols. See https://docs.gradle.org/6.8.3/dsl/or
g.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details.
Configuration on demand is an incubating feature.

说明你配置了除 maven 中央仓库之外的其他不安全的仓库(至于“不安全”在这里的定义,我也不是很清楚,一些国内的镜像仓库例如阿里的也是“不安全”的)
gradle 中有一个属性可以允许 gradle 使用“不安全”的仓库并且不报警告信息
该属性是 allowInsecureProtocol,官方的 Description :Specifies whether it is acceptable to communicate with a repository over an insecure HTTP connection. 翻译过来就是 指定通过不安全的HTTP连接与仓库通信是否可接受,如果该属性的值设置为 true,则表示接受“不安全”的仓库地址

只需要在你的 init.gradle 文件中或者 build.gradle 中进行如下的配置即可:

repositories {
	...
        
    maven {
        allowInsecureProtocol = true
        ...
    }
}
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值