Renato Ivancic - Software Engineer

Background image

Gradle Properties


Project Properties Debugging

Want to see at runtime which properties were passed to your project. You can use the following script to print properties in following order.

  • Gradle extra properties
  • All Gradle properties
  • Arguments to Gradle JVM
  • All system properties

println("==== START EXT Gradle Properties ===="){key, value ->
  println("KEY: $key, VALUE is: $value")
println("==== START Gradle Properties ===="){key, value ->
  println("KEY: $key, VALUE is: $value")
println("==== START Gradle JVM Arguments ====")
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean()
List<String> jvmArgs = runtimeMXBean.getInputArguments()
for (String arg : jvmArgs) {
println("==== START System Properties ====")
System.getProperties().forEach{key, value ->
  println("KEY: $key, VALUE is: $value")

Be aware this can print many properties containing that with sensitive information.

Unfortunately you won’t be able to get access to all command line arguments that were passed with Gradle CLI from the IDE, except if they were passed as project or system properties.

Example resutl when running following command gradlew testTask -i -PprojectProperty=projectProperty -DsystemProperty=systemProperty'

==== START EXT Gradle Properties ====

KEY: projectProperty, VALUE is: projectProperty
KEY: privateArchivaUser, VALUE is: xxx
KEY: privateArchivaPassword, VALUE is: xxx
==== END EXT Gradle Properties ====

==== START Gradle Properties ====
KEY: parent, VALUE is: null
KEY: classLoaderScope, VALUE is: [email protected]6968f5e
KEY: objects, VALUE is: [email protected]
KEY: logger, VALUE is: or[email protected]7bf14e43
KEY: rootDir, VALUE is: /Users/rivancic/Projects/experiment/springboot/beans
==== END Gradle Properties ====

==== START Gradle JVM Arguments ====
==== END Gradle JVM Arguments ====

==== START System Properties ====
KEY: java.specification.version, VALUE is: 15
KEY: kotlinx.coroutines.debug, VALUE is: off
KEY: java.vendor.url, VALUE is:
KEY: file.separator, VALUE is: /
KEY: java.runtime.version, VALUE is: 15.0.2+7
KEY:, VALUE is: rivancic
==== END System Properties ====


How to print all command line arguments passed to gradle? - StackOverflow

Writing Build Scripts - Gradle Userguide

#Gradle #Build tool #Gradle Properties