axiopisty
axiopisty

Reputation: 5137

How to print gradle configuration recursively?

I would like to recursively print a configuration (or any object for that matter) of a gradle build. Is there a way to recursively print all properties of an object in gradle even (especially) if you don't know what all the properties are?

Here is an example.

idea {
  module{
    scopes.COMPILE.plus += configurations.playManaged
    scopes.PROVIDED.plus += configurations.provided

    scopes.each { it ->
        println("[${it}]") // how to replace this with something that will print all properties of the object?
    }
  }
}

In this example, I know scopes has both COMPILE and PROVIDED properties, and each of those has a plus property. But I don't know what other nested properties might exist on these objects. It would be nice to have a function that when passed any object, all properties would be recursively printed to the console, which would allow thoroughly inspecting the object.

Upvotes: 0

Views: 1146

Answers (1)

tim_yates
tim_yates

Reputation: 171114

scopes is a LinkedHashMap, so the best you can do is:

scopes.each { k, v -> println "$k -> $v" }

To print the keys (eg: COMPILE) and their current values.

If it were an object other than a Map, you could do something like:

scopes.getMetaClass().properties.each { println "PROPERTY $it.name" }

But that will just show you class and empty, as it's a Map :-)

Upvotes: 2

Related Questions