要做个 Entry Task ,兴奋地配置了个 Java 的环境,没想到踩了这么多坑。

Plugin was not found in any of the following sources

Spring Boot 官方提供了一个 Spring Intializr 以快速初始化项目,选择了 Gradle Project 之后进入项目,IDEA 的 Gradle 同步上一直报如下错误:

1
2
3
4
5
6
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:
    Gradle Central Plugin Repository

折腾了半天,搜索了无数解决方案都无效,最后根据这个回答才解决。原因现在还没弄清楚,但是能 work 。 解决方案如下:

build.gradle 文件中的 plugins 是这样的:

1
2
3
4
plugins {
	id 'org.springframework.boot' version '2.1.6.RELEASE'
	id 'java'
}

更改一下,将 org.springframework.boot 包移出并去掉版本号:

1
2
3
4
5
plugins {
    id 'java'
}

apply plugin: 'org.springframework.boot'

于是这个错误就解决了 ;)

Plugin with id ‘org.springframework.boot’ not found

然而它会变成另外一个错误,如下:

1
Plugin with id 'org.springframework.boot' not found.

又折腾搜索了一番,发现是缺少 buildscript 。在 build.gradle 文件最前面加入如下内容:

1
2
3
4
5
6
7
8
buildscript {
	repositories {
		mavenCentral()
	}
	dependencies {
		classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.1.6.RELEASE'
	}
}

Problem solved !

Connection to the Internet denied.

遇到这个错误,在 build.gradlerepositories 中换一个 Maven 源即可。

找不到或无法加载主类

在运行 Spring Boot 的时候遇到了这个问题,在命令行上 gradle buildjar 包是能够正常运行的,然而在 IDEA 里就不能通过 Run Application 正常运行。解决方案其实特别特别简单:右键项目中的 src 文件夹,找到 Mark Directory as ,选择 Sources Root ,重新构建运行项目即可。

折腾个环境花了一天,还是得好好学习啊……


知识共享许可协议
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。