我基本上想要在gradle中创建一个执行命令
的任务gradle bootRun -Dspring.profiles.active=test
如果从命令行执行此命令正是我希望它执行的操作但是我没有运气试图在任务上使用type:Exec而在System properties中没有运气
我真的不想把它变成一个用户需要知道要运行的外部命令。我希望它出现在任务/其他任务下。
到目前为止我最接近的尝试:
task bootRunTest() {
executable "gradle"
args "-Dspring.profiles.active=test bootRun"
}
答案 0 :(得分:5)
我试图创造的任务就是:
task bootRunTest(type: org.springframework.boot.gradle.run.BootRunTask, dependsOn: 'build') {
group = 'Application'
doFirst() {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
systemProperty 'spring.profiles.active', 'test'
}
}
答案 1 :(得分:1)
以下是设置要运行的任务的属性的方法,本例中为bootRun
添加 Build.gradle
内部bootRun {
systemProperty "spring.profiles.active", "test,qa,ect"
}
然后从命令行
gradle bootRun
答案 2 :(得分:1)
您也可以将操作系统变量 SPRING_PROFILES_ACTIVE 设置为特定的配置文件。
例如:
SPRING_PROFILES_ACTIVE=dev gradle clean bootRun