BAEL-4371: Finished code samples
This commit is contained in:
parent
691a948c5f
commit
d19ac51aaa
@ -1,16 +1,46 @@
|
|||||||
apply plugin: "java"
|
apply plugin: "java"
|
||||||
|
apply plugin: "application"
|
||||||
description = "Gradle Command Line Arguments examples"
|
description = "Gradle Command Line Arguments examples"
|
||||||
|
|
||||||
|
ext.javaMainClass = "com.baeldung.cmd.MainClass"
|
||||||
|
|
||||||
|
application {
|
||||||
|
mainClassName = javaMainClass
|
||||||
|
}
|
||||||
|
|
||||||
task propertyTypes(){
|
task propertyTypes(){
|
||||||
doLast{
|
doLast{
|
||||||
if (project.hasProperty('input')){
|
project.getProperties().values().each {
|
||||||
println "This is my property ["+ project.getProperty('input')+"]"
|
println "Project property ["+it+"]"
|
||||||
} else {
|
}
|
||||||
println "No property was passed"
|
|
||||||
|
System.getProperties().each {
|
||||||
|
println "System property ["+it+"]"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.baeldung.cmd;
|
||||||
|
|
||||||
|
public class MainClass {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Gradle command line arguments example");
|
||||||
|
for (String arg : args) {
|
||||||
|
System.out.println("Got argument [" + arg + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user