解決 Gradle 無法導入套件問題
最近開始複習以前寫過的項目,不知道是不是環境改變,開啟項目後無法正常執行項目裡面的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 從下述
1 2 3 4 |
plugins { id 'org.springframework.boot' version '2.1.6.RELEASE' id 'java' } |
改為
1 2 3 4 5 |
plugins { id 'java' } apply plugin: 'org.springframework.boot' |
最後在 build.gradle 文件最前面加入 如下配置
1 2 3 4 5 6 7 8 |
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 並在最底下加入 如下配置
1 |
rootProject.buildFileName = 'build.gradle.kts' |
雖然 Build Configuration 會通過,但依賴並沒有正常導入,推測可能是 Kotlin 有關,反正無法解決問題。
相逢就是有緣,留下足跡吧!