gradletooling

Can I use the gradle connector to get arbitrary configuration information from a build.gradle file?


I'm using the Gradle connector with a Gradle project that is downloaded from a service. I want to do some Gradle operations on that project but need some information from the project.

The downloaded project's build.gradle has some properties that I would like to extract :

group = "value0"
archivesBaseName = "value1"
version = "value2"

If I use

ProjectConnection.getModel(GradleProject.class)

I can get some values from the model but not those ones that I want (perhaps I am using it wrong?). Is there a way to extract those specific values out of the project (perhaps a different model)? I can also just do some text parsing on the build file, but I'd like that to be my last option.


Solution

  • The Gradle tooling API only exposes a subset of the build script information, using its own models. As far as I can tell, the properties that you are interested in are not exposed by default. However, you can expose your own custom model. For an example, see samples/toolingApi/customModel in the full Gradle distribution.