2020-08-31 15:53:30 -04:00
|
|
|
apply plugin: "java"
|
2020-09-01 11:52:06 -04:00
|
|
|
apply plugin: "application"
|
2020-08-31 15:53:30 -04:00
|
|
|
description = "Gradle Command Line Arguments examples"
|
|
|
|
|
2020-09-01 11:52:06 -04:00
|
|
|
ext.javaMainClass = "com.baeldung.cmd.MainClass"
|
2020-08-31 15:53:30 -04:00
|
|
|
|
2020-09-01 11:52:06 -04:00
|
|
|
application {
|
|
|
|
mainClassName = javaMainClass
|
|
|
|
}
|
2020-08-31 15:53:30 -04:00
|
|
|
|
|
|
|
task propertyTypes(){
|
|
|
|
doLast{
|
2020-09-03 08:46:48 -04:00
|
|
|
if (project.hasProperty("args")) {
|
|
|
|
println "Our input argument with project property ["+project.getProperty("args")+"]"
|
2020-08-31 15:53:30 -04:00
|
|
|
}
|
2020-09-03 08:46:48 -04:00
|
|
|
println "Our input argument with system property ["+System.getProperty("args")+"]"
|
2020-08-31 15:53:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-01 11:52:06 -04:00
|
|
|
if (project.hasProperty("args")) {
|
|
|
|
ext.cmdargs = project.getProperty("args")
|
|
|
|
} else {
|
2020-09-03 08:46:48 -04:00
|
|
|
ext.cmdargs = "ls"
|
2020-09-01 11:52:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
task cmdLineJavaExec(type: JavaExec) {
|
|
|
|
group = "Execution"
|
|
|
|
description = "Run the main class with JavaExecTask"
|
|
|
|
classpath = sourceSets.main.runtimeClasspath
|
|
|
|
main = javaMainClass
|
2020-09-03 08:46:48 -04:00
|
|
|
args cmdargs.split()
|
2020-09-01 11:52:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
task cmdLineExec(type: Exec) {
|
|
|
|
group = "Execution"
|
2020-09-03 08:46:48 -04:00
|
|
|
description = "Run the an external program with ExecTask"
|
|
|
|
commandLine cmdargs.split()
|
2020-09-01 11:52:06 -04:00
|
|
|
}
|