Over a million developers have joined DZone.

Passing System Properties With Gradle

DZone's Guide to

Passing System Properties With Gradle

How to pass Java system properties from the command-line to a Java process in a Gradle build file using Grails 3.

· DevOps Zone
Free Resource

Download “The DevOps Journey - From Waterfall to Continuous Delivery” to learn about the importance of integrating automated testing into the DevOps workflow, brought to you in partnership with Sauce Labs.

In a previous post we learned how to pass Java system properties from the command-line to a Java process defined in a Gradle build file. Because Grails 3 uses Gradle as the build tool we can apply the same mechanism in our Grails application. We need to reconfigure the run task. This task is of typeJavaExec and we can use the method systemProperties to assign the system properties we define on the command-line when we invoke the runtask.

We have a simple Grails 3 application with the following controller that tries to access the Java system property sample.message:

// File: grails-app/controllers/com/mrhaki/grails/SampleController.groovy
package com.mrhaki.grails

class SampleController {

    def index() {
        final String message =
            System.properties['sample.message'] ?: 'gr8'
        render "Grails is ${message}!"
Next we configure the  run and  bootRun tasks and use  System.properties with the Java system properties from the command-line as argument for the  systemProperties method:

// File: build.gradle

[run, bootRun].each { runTask ->
    configure(runTask) {
        systemProperties System.properties


Now we can invoke the run or bootRun tasks with Gradle:

$ gradle -Dsample.message=cool run

Or we can execute the run-app command with the grails command:

grails> run-app -Dsample.message=cool

Discover how to optimize your DevOps workflows with our cloud-based automated testing infrastructure, brought to you in partnership with Sauce Labs

gradle ,grails ,devops ,build tool

Published at DZone with permission of Hubert Klein Ikkink, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}