Gradle7.1忽略https檢查

問題描述

Gradle7下使用http私庫(kù)時(shí),提示要使用 https, 可以使用 allowInsecureProtocol true 關(guān)閉。

Could not resolve all dependencies for configuration ':compileClasspath'.
Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository 'maven(http://127.0.0.1:8081/repository/maven-public/)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols. See https://docs.gradle.org/7.1/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details. 

但是該屬性在舊版Gradle(例如5.6.2)中不存在,會(huì)提示錯(cuò)誤;

解決方式

init.gradle 文件位置: C:\Users\[用戶名]\.gradle

init.gradle中,檢查 ArtifactRepository 對(duì)象中是否存在 allowInsecureProtocol屬性,如果存在才設(shè)置,否則忽略;最終 init.gradle 配置文件如下。

allprojects {
    def REPOSITORY_URL = 'http://127.0.0.1:8081/repository/maven-public/'
    repositories {
        mavenLocal()
        maven { ArtifactRepository repo ->
            // 判斷屬性是否存在,之后再設(shè)置
            if (repo.metaClass.hasProperty(repo, 'allowInsecureProtocol')) {
                allowInsecureProtocol true
            }
            url REPOSITORY_URL
        }
        mavenCentral()
    }

    buildscript {
        repositories {
            mavenLocal()
            maven { ArtifactRepository repo ->
                // 判斷屬性是否存在,之后再設(shè)置
                if (repo.metaClass.hasProperty(repo, 'allowInsecureProtocol')) {
                    allowInsecureProtocol true
                }
                url REPOSITORY_URL
            }
            mavenCentral()
        }
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容