解決 Gradle 無法導入套件問題

5,904次閱讀
尚無留言

共计 1075 个字符,预计需要花费 3 分钟才能阅读完成。

最近開始複習以前寫過的項目,不知道是不是環境改變,開啟項目後無法正常執行項目裡面的 Gradle 腳本,經過推敲測試總算解決問題,以下開始記錄

遇到的錯誤訊息如下

* What went wrong:
Plugin [id: ‘org.springframework.boot’, version: ‘2.1.6.RELEASE’] was not found in any of the following sources:

– Gradle Core Plugins (plugin is not in ‘org.gradle’ namespace)
– Plugin Repositories (could not resolve plugin artifact ‘org.springframework.boot:org.springframework.boot.gradle.plugin:2.1.6.RELEASE’)
Searched in the following repositories:
maven(http://maven.aliyun.com/nexus/content/groups/public/)
MavenRepo

方法 1: 修改 build.gradle

參考 配置 Gradle (IDEA) 环境的坑 這篇文章 需要修改 build.gradle 文件中 plugins 從下述

plugins {
    id 'org.springframework.boot' version '2.1.6.RELEASE'
    id 'java'
}

改為

plugins {id 'java'}

apply plugin: 'org.springframework.boot'

最後在 build.gradle 文件最前面加入 如下配置

buildscript {
    repositories {url "https://plugins.gradle.org/m2/"}
    dependencies {classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.1.6.RELEASE'}
}

即可正常匯入項目並自動導入引用

方法 2: 修改 settings.gradle

參考 Gradle Core Plugins (plugin is not in ‘org.gradle’ namespace) 解決問題

找到 settings.gradle 並在最底下加入 如下配置

rootProject.buildFileName = 'build.gradle.kts'

雖然 Build Configuration 會通過,但依賴並沒有正常導入,推測可能是 Kotlin 有關,反正無法解決問題。

正文完
 0
評論(尚無留言)

夜升筆談

夜升筆談
夜升筆談
視寫代碼為信仰,奉高效能為執著,成為大牛不是一蹴可幾,但只要秉持信念終究能成,我依舊在這條路上不斷前進。
最新评论
Yosheng Yosheng 我是买梯子了 只是理解一下原理而已
虚拟信用卡 虚拟信用卡 还是直接买梯子吧,太浪费时间了
spring spring 学习了
cskepper cskepper 非常有用,已经顺利解决
cskepper cskepper 非常有用,已经顺利解决
Yosheng Yosheng 這可能是代理服務器的問題了...
淑淑 淑淑 我在大陸使用了VPN 照著你說的操作 但是出現無法透過代理伺服器連線 我的電腦是W7 也下載了兼容版 用了大概一個星期後今天LINE就無法使用VPN了 這種要怎樣解決
Yosheng Yosheng 如果不能直接撥放建議直接下載回來播放,後面我就沒去折騰為什麼不能線上播放了
SADFISH SADFISH 我无法播放语音是为什么呀楼主
Yosheng Yosheng 微信号 yosheng0323