在执行一个gradle构建任务时,报如下错
> Task :extractIncludeProto FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':extractIncludeProto'.
> Could not resolve all dependencies for configuration ':compileProtoPath'.
> Using insecure protocols with repositories, without explicit opt-in, is unsupported.
* Try:
> Switch Maven repository 'maven(http://maven.aliyun.com/nexus/content/groups/public)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols.
> For more information, please refer to https://docs.gradle.org/8.3/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol in the Gradle documentation.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 676ms
1 actionable task: 1 executed
根据提示可知,是配置的仓库使用了不安全的http协议,需要更改下Maven仓库配置。但为什么会使用到Maven仓库,我找到项目下的build.gradle文件,发现有这么一段配置。
repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/maven2/" }
mavenCentral()
mavenLocal()
}
其中mavenCentral()、mavenLocal()就是设置了maven仓库。
在mac os下,找到家目录下的 ~/.gradle/init.gradle文件,原内容为
allprojects {
repositories {
maven {
url "http://maven.aliyun.com/nexus/content/groups/public"
}
}
}
修改文件中的内容为https,即为
allprojects {
repositories {
maven {
url "https://maven.aliyun.com/nexus/content/groups/public"
}
}
}
保存后再运行构建任务就成功了,以此记录一下!
当然也可以修改项目下的build.gradle文件,在仓库配置中加入allowInsecureProtocol = true
repositories {
// maven { // The google mirror is less flaky than mavenCentral()
// url "https://maven-central.storage-download.googleapis.com/maven2/" }
// mavenCentral()
// mavenLocal()
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}