Android库项目jitci.com构建失败:未配置HTTP仓库却提示缓存仓库不安全
问题
我在Android库项目中使用buildSrc模块,在jitci.com执行JitPack构建时失败,但本地项目可正常构建运行,且jitpack.io官网的JitPack构建也能成功,构建产物可作为依赖在其他Android项目中使用。我从未配置过cache(http://cache)这个HTTP仓库,也没有使用任何不安全HTTP协议的仓库,为何仅在jitci.com构建时出现以下错误?
settings.gradle 文件
pluginManagement { repositories { gradlePluginPortal() google() mavenCentral() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() maven { url 'https://jitpack.io' } } } rootProject.name = "ComposeComponents" include ':app' include ':compose-components'
buildSrc模块下的build.gradle 文件
import org.gradle.kotlin.dsl.`kotlin-dsl` plugins { `kotlin-dsl` } repositories { mavenCentral() }
jitci.com构建错误信息
A problem occurred configuring project ':buildSrc'. > Could not resolve all dependencies for configuration ':buildSrc:classpath'. > Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository 'cache(http://cache)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols. See https://docs.gradle.org/7.3.3/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details.
原因与解决办法
原因
jitci.com的JitPack构建环境会内部自动添加http://cache这个HTTP协议的缓存仓库,而你的buildSrc模块没有针对这个仓库做配置。Gradle 7及以上版本默认禁用不安全HTTP协议的仓库,未显式允许时会直接报错。本地和jitpack.io官网的构建环境没有添加这个内部缓存仓库,所以不会触发错误。
解决办法
可以通过两种方式解决:
方法1:显式允许该缓存仓库的不安全协议
修改buildSrc模块下的build.gradle,添加对http://cache仓库的配置,开启不安全协议允许:
import org.gradle.kotlin.dsl.`kotlin-dsl` plugins { `kotlin-dsl` } repositories { mavenCentral() // 适配jitci环境的内部缓存仓库,允许不安全HTTP协议 maven { uri("http://cache") isAllowInsecureProtocol = true } }
方法2:强制buildSrc仅使用你指定的仓库
在buildSrc模块下新建settings.gradle.kts文件,配置仓库模式为禁止项目外的仓库,阻断环境自动添加的仓库:
dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { mavenCentral() } }
这样就能避免jitci环境自动添加的不安全仓库触发Gradle的协议限制错误。
内容的提问来源于stack exchange,提问作者Raj Narayanan
相关产品推荐
相关产品推荐

