2020-08-31 22:53:30 +03:00
|
|
|
apply plugin: "java"
|
2020-09-01 18:52:06 +03:00
|
|
|
apply plugin: "application"
|
2020-08-31 22:53:30 +03:00
|
|
|
description = "Gradle Command Line Arguments examples"
|
|
|
|
|
2020-09-01 18:52:06 +03:00
|
|
|
ext.javaMainClass = "com.baeldung.cmd.MainClass"
|
2020-08-31 22:53:30 +03:00
|
|
|
|
2020-09-01 18:52:06 +03:00
|
|
|
application {
|
|
|
|
mainClassName = javaMainClass
|
|
|
|
}
|
2020-08-31 22:53:30 +03:00
|
|
|
|
|
|
|
task propertyTypes(){
|
|
|
|
doLast{
|
2020-09-01 18:52:06 +03:00
|
|
|
project.getProperties().values().each {
|
|
|
|
println "Project property ["+it+"]"
|
|
|
|
}
|
|
|
|
|
|
|
|
System.getProperties().each {
|
|
|
|
println "System property ["+it+"]"
|
2020-08-31 22:53:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-01 18:52:06 +03:00
|
|
|
if (project.hasProperty("args")) {
|
|
|
|
ext.cmdargs = project.getProperty("args")
|
|
|
|
ext.cmdargsarray = cmdargs.split()
|
|
|
|
} else {
|
|
|
|
ext.cmdargs = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
task cmdLineJavaExec(type: JavaExec) {
|
|
|
|
group = "Execution"
|
|
|
|
description = "Run the main class with JavaExecTask"
|
|
|
|
classpath = sourceSets.main.runtimeClasspath
|
|
|
|
main = javaMainClass
|
|
|
|
args cmdargsarray
|
|
|
|
}
|
|
|
|
|
|
|
|
ext.cmdarray = ["java", "-classpath", sourceSets.main.runtimeClasspath.getAsPath(), javaMainClass]
|
|
|
|
cmdarray = (cmdarray << cmdargsarray).flatten()
|
|
|
|
|
|
|
|
task cmdLineExec(type: Exec) {
|
|
|
|
dependsOn build
|
|
|
|
group = "Execution"
|
|
|
|
description = "Run the main class with ExecTask"
|
|
|
|
commandLine cmdarray
|
|
|
|
}
|