Search code examples
grailsgradlegrails-3.0

Passing command Line Arguments for grails run-app through gradle task


I have a grails 3 application for which I am trying to pass command line arguments to my application when I am running it through gradle bootRun task.

I want to read the arguments in my config file for runtime operations. As per the grails documentation for yml configration here I tried to add the following to my build.gradle file

run {
    systemProperties = System.properties
}

When I add that configuration and run my task I get the following error:

3:11:20 PM: Executing external task 'bootRun -Dcolor=red -Dfruit=apple'...

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\docs\projects\jet\build.gradle' line: 85

* What went wrong:
A problem occurred evaluating root project 'jet'.
> Could not find method run() for arguments [build_6lnm3xriwcnri1zrvfit1niuu$_run_closure8@4446881a] on root project 'jet'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 8.892 secs
Could not find method run() for arguments [build_6lnm3xriwcnri1zrvfit1niuu$_run_closure8@4446881a] on root project 'jet'.
3:11:32 PM: External task execution finished 'bootRun -Dcolor=red -Dfruit=apple'.

Please let me know if there is anything I am missing here or if there is a better way of doing this.


Solution

  • So I find out what the issue was.

    Grails 3.0 uses bootRun as target instead of run. Changing adding the below code fixed the issue.

    bootRun {
        systemProperties = System.properties
    }
    

    Hope this helps everyone.