我在试图将春布特人军的参数纳入我从指挥线提出的申请时就发现了这一点。 (一百万分之7.6)
首先,在您的build.gradle档案中:
if (project.hasProperty("args")) {
ext.cmdargs = project.getProperty("args")
} else {
ext.cmdargs = ""
}
随后,在build.gradle文档中:
task runDemo(dependsOn: jar ) {
doLast {
javaexec {
classpath = sourceSets.main.runtimeClasspath
jvmArgs = [ "-Xmx8G" ]
mainClass = "my.demo.app.App"
args cmdargs.split()
}
}
}
接着,为了在巴什指挥线上开展“白血”活动,你做了以下工作:
$ ./gradlew runDemo -Pargs= arg1 -arg2 --arg3
--spring.datasource.username=myusername
--spring.datasource.password=mypassword
--spring.datasource.driver-class-name=some.sql.Driver
一些说明:
- -P creates a property, args in this case, that is passed to gradle.
- The args property value is enclosed in single quotes.
- Because I m using bash and my args property value spanned multiple lines, I didn t have to do anything special because of how bash interprets text contained within single quotes. Specifically, you do not need a backslash on the end of each line to continue on the next line within the text bounded by single quotes.
- The build.gradle file reads the args property and puts the value in ext.cmdargs. Then, the runDemo task calls cmdargs.split() and puts the resulting array into the args variable that is passed into you application.