一、使用idea创建spring boot项目
创建完目录结构:
初始的build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.3'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'com.binbinxiu'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
二、gradle替换仓库地址
首先替换仓库地址更快速的下载依赖
gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
# 替换下载gradle插件地址
distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
build.gradle
repositories {
mavenLocal()
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
}
三、安装Spock依赖
build.gradle
添加spock测试依赖
plugins {
id 'java'
id 'groovy'
id 'org.springframework.boot' version '3.2.3'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'com.binbinxiu'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
repositories {
mavenLocal()
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
}
dependencies {
testImplementation(
'junit:junit:4.12',
'org.springframework.boot:spring-boot-test-autoconfigure',
'org.spockframework:spock-core:2.4-M2-groovy-4.0',
'org.spockframework:spock-unitils:2.4-M2-groovy-4.0',
'org.spockframework:spock-spring:2.4-M2-groovy-4.0'
)
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.jupiter', module: 'junit-jupiter' // 排除JUnit Jupiter模块
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' // 排除JUnit Jupiter模块
}
implementation 'org.springframework.boot:spring-boot-starter-web'
}
sourceSets {
test {
java {srcDirs=[]}
groovy {srcDirs = ["src/test/java","src/test/groovy"]}
}
}
四:构建
右侧gradle侧边栏,点击build
看到BUILD SUCCESSFUL 构建成功