I am trying to pass an argument from the command line to a java class. I followed this post: http://gradle.1045684.n5.nabble.com/Gradle-application-plugin-question-td5539555.html , but the code does not work for me (maybe it is not intended for JavaExec?). Here is what I tried:
task listTests(type:JavaExec){ main = "util.TestGroupScanner" classpath = sourceSets.util.runtimeClasspath // this works... args 'demo' /* // this does not work! if (project.hasProperty("group")){ args group } */ }
The output from the above value of the argument is:
C:\ws\svn\sqe\sandbox\selenium2forbg\testgradle>g listTests :compileUtilJava UP-TO-DATE :processUtilResources UP-TO-DATE :utilClasses UP-TO-DATE :listTests Received argument: demo BUILD SUCCESSFUL Total time: 13.422 secs
However, as soon as I changed the code to use the hasProperty section and passed "demo" as an argument on the command line, I get a NullPointerException:
C:\ws\svn\sqe\sandbox\selenium2forbg\testgradle>g listTests -Pgroup=demo -s FAILURE: Build failed with an exception. * Where: Build file 'C:\ws\svn\sqe\sandbox\selenium2forbg\testgradle\build.gradle' line:25 * What went wrong: A problem occurred evaluating root project 'testgradle'. > java.lang.NullPointerException (no error message) * Try: Run with --info or --debug option to get more log output. * Exception is: org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'testgradle'. at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54) at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:127) at org.gradle.configuration.BuildScriptProcessor.evaluate(BuildScriptProcessor.java:38)
There is a simple test project at http://gradle.1045684.n5.nabble.com/file/n5709919/testgradle.zip that illustrates the problem.
Used Gradle 1.0-rc-3. NullPointer from this line of code:
args group
I added the following task before the task definition, but it did not change the result:
group = hasProperty('group') ? group : 'nosuchgroup'
Any pointers on how to pass command line arguments to Gradle.
gradle
Lidia Jul 27 '12 at 22:34 2012-07-27 22:34
source share