https://stackoverflow.com/a/23689696/1757491
I started using some info from the proposed solution from the above answer: Application Plugin Approach
(build.gradle)
apply plugin: 'application'
mainClassName = "com.mycompany.MyMain"
run {
/* Need to split the space-delimited value in the exec.args */
args System.getProperty("exec.args").split()
}
Command Line:
gradle run -Dexec.args="arg1 arg2 arg3"
it works great for its intended purpose but seems to have a side effect. It makes sense to pass in the command line arguments for run but I have to pass them in for every task for example:
gradle tasks -Dexec.args="arg1 arg2 arg3"
If I leave out the
-Dexec.args="arg1 arg2 arg3"
I get
"build failed with an exception"
Where:path\build.gradle line:18 which if where my run{ } is.
Right click Build Specifications in the Project Explorer of the completed project. Select new>>Application (EXE) Navigate to the Advanced category. Check the Pass all command line arguments to application box (Figure 3)
It is possible to pass custom command line arguments to the test module.
You can solve it a two different ways:
First:
exec.args
property can be read directly in the main class - so there's no need to configure args
in run
closure at all.
Second:
Just if it:
execArgs = System.getProperty('exec.args')
if(execArgs)
args = execArgs.split()
Edited by Question Asker: using if does work but I had to change the syntax slightly.
if(System.getProperty("exec.args") != null) {
args System.getProperty("exec.args").split()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With