How can I get a specific property with gradle command line?

Hi Everbody,

I just need to list java.srcDirs property … so How can I get a specific property I already know how to list all properties but I haven’t seen how can I get deep property ?

Thanks

You’ll have to be a little more specific. You can specify the “srcDirs” property of either the “main” or “test” group of a sourceSet, and the same property for custom groups of any sourceSet.

You could do something like this, but I have no idea what you’re trying to do:

task printSrcDirs() << {
 sourceSets.main.java.srcDirs.each { println it }
 }

Thanks for the reply … I have an other question if you allow which jar can I use to read gradle file ?

Sorry, but I have no idea what you mean by that. Again, please be more specific.

My aim is to parse the gradle file used by android studio projects, but I notified that Gradle isn’t 100% groovy (http://stackoverflow.com/questions/28658851/impossible-to-read-the-content-of-the-input-stream-for-file-named-build-gradle) so I just need to parse them how can I do that ?

Why are you trying to do that? What is your end goal?

I am parsing an Android Studio project and I need to get the source path from build.gradle file

Why? Why do you believe you need to do this? If you need to have an external process get this information, you could just write a task to print the property in your build script and have the external process run that task.

The other thing to realize is that if you’ve decided you need to do some processing that requires “parsing” the Gradle build script, just following on from my last comment, you should realize that you can write a Gradle task to do almost anything. You can write a task to print out a property value, as I described, but there’s not much point in having Gradle print out a property value and having some other scripting language do something with it. If you have a Gradle build script, and you need some other automation around it, just write the automation in the Gradle build script.