构建 Spring Boot Web 应用程序示例
版本 9.0.0
您可以在支持Gradle的IDE中打开此示例。 |
此示例展示了如何使用 Gradle 构建 Spring Boot Web 应用程序。该应用程序是使用 Spring Initializr 生成的。
app/build.gradle.kts
plugins {
id("org.springframework.boot") version("3.4.3")
id("java")
}
version = "1.0.2"
group = "org.gradle.samples"
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
repositories {
mavenCentral()
}
dependencies {
implementation(platform("org.springframework.boot:spring-boot-dependencies:3.4.3"))
implementation("org.springframework.boot:spring-boot-starter")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
tasks.named<Test>("test") {
useJUnitPlatform()
}
app/build.gradle
plugins {
id("org.springframework.boot") version("3.4.3")
id("java")
}
version = '1.0.2'
group = 'org.gradle.samples'
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
repositories {
mavenCentral()
}
dependencies {
implementation(platform("org.springframework.boot:spring-boot-dependencies:3.4.3"))
implementation("org.springframework.boot:spring-boot-starter")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
tasks.named('test', Test) {
useJUnitPlatform()
}
构建并运行应用程序
$ ./gradlew bootRun > Task :app:bootRun . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.2.1.RELEASE) 2019-11-12 22:14:43.819 INFO 1389 --- [ main] o.g.samples.SpringBootDemoApplication : Starting SpringBootDemoApplication on localhost with PID 1389 (/home/user/build/classes/java/main started by user in /home/user) 2019-11-12 22:14:43.820 INFO 1389 --- [ main] o.g.samples.SpringBootDemoApplication : No active profile set, falling back to default profiles: default 2019-11-12 22:14:44.108 INFO 1389 --- [ main] o.g.samples.SpringBootDemoApplication : Started SpringBootDemoApplication in 5.537 seconds (JVM running for 5.8) BUILD SUCCESSFUL 3 actionable tasks: 3 executed
欲了解更多信息,建议阅读Gradle 入门。您还可以在Spring 团队提供的指南中找到与 Spring Boot 相关的信息。