DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Security Is a Platform Property, Not a Pipeline Step
  • An XGBoost Property Valuation Postmortem: Leakage, Overfitting, and SHAP Surprises
  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Introduce a New API Quickly Using Spring Boot and Gradle

Trending

  • The Java Story: The Official Documentary Is Here
  • Retrieval Augmented Generation With Spring AI 2.0, Claude, and PGvector
  • GraphRAG Retrieval Is Three Decisions: Granularity, Mechanism, and Paradigm
  • Orchestrating Trusted Environments: Securing Untrusted Code Execution With Docker and GKE Agent Sandbox

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.

By 
Hubert Klein Ikkink user avatar
Hubert Klein Ikkink
·
Oct. 01, 15 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
14.6K Views

Join the DZone community and get the full member experience.

Join For Free

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
Property (programming) Gradle

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

Opinions expressed by DZone contributors are their own.

Related

  • Security Is a Platform Property, Not a Pipeline Step
  • An XGBoost Property Valuation Postmortem: Leakage, Overfitting, and SHAP Surprises
  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Introduce a New API Quickly Using Spring Boot and Gradle

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook