I am creating an automation solution that needs to parse and read a Gradle build, including build.gradle
, settings.gradle
, and gradle.properties
, and any submodules. I know there is an API that include the Project
class, which seems to be what I want. The problem is that it is not obvious how to get an instance of a Project
class.
Where in the API is the code to parse the build and return a Project
instance?
You'll have to use Gradle's Tooling API. The entry point is GradleConnector
class:
try(
ProjectConnection connection = GradleConnector.newConnector()
.forProjectDirectory(new File("/path/to/project"))
.connect()
) {
GradleProject project = connection.getModel(GradleProject.class);
// Do some things with the project
// project.getTasks().forEach(task -> { ... });
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With