使用 Gradle 运行应用
原文:https://docs.spring.io/spring-boot/gradle-plugin/running.html (Spring Boot 4.2.0)
Spring Boot Gradle 插件的 bootRun 任务以展开形式运行应用。
向应用传递参数
可以通过 bootRun 任务的 args 属性传递参数:
tasks.named('bootRun') { args '--server.port=8081' }
向应用传递系统属性
通过 systemProperty 设置系统属性:
tasks.named('bootRun') { systemProperty 'spring.profiles.active', 'dev' }
重新加载资源
如果要将静态资源直接添加到类路径以支持热重载,可以设置 sourceResources:
tasks.named('bootRun') { sourceResources sourceSets.main }
使用测试主类
可以通过配置 bootRun 使用测试类路径和测试主类:
tasks.named('bootRun') { classpath = sourceSets.test.runtimeClasspath mainClass = 'com.example.MyTestApplication' }