在我的build.gradle
我有一项任务:
run {
dependsOn ':jar'
args = [ 'run', project.mainVerticleName, '-cluster', "-launcher-class=$mainClassName", '-Denvironment=development' ]
}
我想指定命令行参数并在我的课程中阅读它们。
我试过了:
.\gradlew.bat run -Dhttpport=8825 -Phttpport=8825
但我班上的行:
log.info "port = ${System.getProperty( 'httpport' )}"
log.info "port = ${System.getenv( 'httpport' )}"
两种情况都记录null
。
我错过了什么?
答案 0 :(得分:3)
此:
.\gradlew.bat run -Dhttpport=8825
您将系统属性传递给gradle本身,而不是它将启动的进程。要使其以这种方式工作,您需要按如下方式配置run
:
run {
dependsOn ':jar'
args = [ 'run', project.mainVerticleName, '-cluster', "-launcher-class=$mainClassName", '-Denvironment=development' ]
systemProperties System.properties
}
和
.\gradlew.bat run -Dhttpport=8825
您还可以使用项目属性(-P
)配置系统属性,以便:
run {
dependsOn ':jar'
args = [ 'run', project.mainVerticleName, '-cluster', "-launcher-class=$mainClassName", '-Denvironment=development' ]
systemProperties [httpport:project.httpport]
}
然后:
.\gradlew.bat run -Phttpport=8825