diff --git a/gradle-5/cmd-line-args/build.gradle b/gradle-5/cmd-line-args/build.gradle new file mode 100644 index 0000000000..15c9288024 --- /dev/null +++ b/gradle-5/cmd-line-args/build.gradle @@ -0,0 +1,38 @@ +apply plugin: "java" +apply plugin: "application" +description = "Gradle Command Line Arguments examples" + +ext.javaMainClass = "com.baeldung.cmd.MainClass" + +application { + mainClassName = javaMainClass +} + +task propertyTypes(){ + doLast{ + if (project.hasProperty("args")) { + println "Our input argument with project property ["+project.getProperty("args")+"]" + } + println "Our input argument with system property ["+System.getProperty("args")+"]" + } +} + +if (project.hasProperty("args")) { + ext.cmdargs = project.getProperty("args") +} else { + ext.cmdargs = "ls" +} + +task cmdLineJavaExec(type: JavaExec) { + group = "Execution" + description = "Run the main class with JavaExecTask" + classpath = sourceSets.main.runtimeClasspath + main = javaMainClass + args cmdargs.split() +} + +task cmdLineExec(type: Exec) { + group = "Execution" + description = "Run an external program with ExecTask" + commandLine cmdargs.split() +} diff --git a/gradle-5/cmd-line-args/src/main/java/com/baeldung/cmd/MainClass.java b/gradle-5/cmd-line-args/src/main/java/com/baeldung/cmd/MainClass.java new file mode 100644 index 0000000000..f00aa07d72 --- /dev/null +++ b/gradle-5/cmd-line-args/src/main/java/com/baeldung/cmd/MainClass.java @@ -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 + "]"); + } + } +} diff --git a/gradle-5/settings.gradle b/gradle-5/settings.gradle index 5384d071e7..ede73daf0a 100644 --- a/gradle-5/settings.gradle +++ b/gradle-5/settings.gradle @@ -1,4 +1,5 @@ rootProject.name='gradle-5-articles' include 'java-exec' include 'unused-dependencies' -include 'source-sets' \ No newline at end of file +include 'source-sets' +include 'cmd-line-args' \ No newline at end of file