Spring boot springboot中测试的Gradle命令行参数
我想将一个参数传递给Gradle test(覆盖application.properties中的某些属性) 有一种方法可以在执行bootRun时传递参数。检查,例如: ./gradlew bootRun-Pargs=--some.property=changedvalue 但我想在测试中这样做,比如:Spring boot springboot中测试的Gradle命令行参数,spring-boot,build.gradle,Spring Boot,Build.gradle,我想将一个参数传递给Gradle test(覆盖application.properties中的某些属性) 有一种方法可以在执行bootRun时传递参数。检查,例如: ./gradlew bootRun-Pargs=--some.property=changedvalue 但我想在测试中这样做,比如: ./gradlew test-Pargs=-some.property=changedvalue适合我。我将命令行参数传播到系统属性 test { if (project.hasPrope
./gradlew test-Pargs=-some.property=changedvalue适合我。我将命令行参数传播到系统属性
test {
if (project.hasProperty('args')) {
project.args.split(',').each {
def (key, value) = it.replaceFirst('--', "").split('=')
systemProperty ((String)key, (String)value)
}
}
useJUnitPlatform()
}
下面的命令行可以很好地工作
./gradlew test -Pargs=--some.property=changedvalue