3

I am using Gradle tooling API to get different insights about Gradle projects such as project tasks, Gradle version, and more.

Part of this analysis requires me to know what plugins were applied (directly and transitively) by the project. I could not find a way to get Project’s plugins from the tooling API. Is there a way to do it?

Cœur
  • 37,241
  • 25
  • 195
  • 267
slashms
  • 928
  • 9
  • 26

1 Answers1

1

The tooling API is limited in how you can query a build and there's no API to list build plugins, but the tooling API allows you to add your own plugins & models which you can use to query the build.

It's a little complex, but you need to add an init script to the build (eg via init.gradle) to provide your custom model & plugin to query the build.

This is a good repo that demonstrates how to do it: https://github.com/melix/gradle-tapi-demo-artifacts

Here's some code from that repo that demonstrates how to list build artifacts with a custom plugin & model:

ModelBuilder<OutgoingArtifactsModel> customModelBuilder = connection.model(OutgoingArtifactsModel.class);
customModelBuilder.withArguments("--init-script", copyInitScript().getAbsolutePath());
OutgoingArtifactsModel model = customModelBuilder.get();
for (File artifact : model.getArtifacts()) {
    System.out.println("artifact = " + artifact);
}

If you want to list plugins you can use the project.getPlugins() API.

badsyntax
  • 9,394
  • 3
  • 49
  • 67
  • ..Can you please suggest on [How to determine the deployment url, uploadArchive task will pick at runtime](https://stackoverflow.com/questions/62838908/need-to-capture-activity-of-the-uploadarchive-and-publish-gradle-tasks?bcsi_scan_edc08cf19929fe1d=ZIDqjWalvKjvXYnxgbeS6WJznPgPAAAAFDlriA==) For uploadArchive task, based on artifact version or release type . It can pick SnapshotURL or ReleaseURL. how to get the deployment URL at runtime. I want to read that url in init.gradle ? Please suggest. – user3142041 Jul 22 '20 at 09:44