紀錄一下Spring boot 2.7.5設置的兩種方式,公司透過spring initializer下載下來的build一執會有錯誤訊息,使用legacy plugin的方式設定才成功

由spring initializer設定的結果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

group = 'com.swj.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
useJUnitPlatform()
}

Using legacy plugin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
buildscript {
repositories {
maven {
alloInsecureProtocal = true
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.7.5"
classpath "'io.spring.dependency-management' version '1.0.15.RELEASE'"
}
}
allprojects {
repositories {
alloInsecureProtocal = true
url "https://plugins.gradle.org/m2/"
}
}
apply plugin: 'org.springframework.boot'
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'

group = 'com.swj.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
useJUnitPlatform()
}

踩過的坑

Could not set unknown property ‘sourceCompatibility’ for root project

解決方式:加入apply plugin:‘java’


reference