gamerson
gamerson

Reputation: 5310

How do I get the plugins applied to a build script using gradle tooling api?

I'm writing an Eclipse plugin and I want to use the gradle tooling api to inspect a gradle project's build script to look whether or not it has certain plugins applied.

Lets say that I have a build script that looks something like this:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'org.dm.gradle:gradle-bundle-plugin:0.6.2'
    }
}

apply plugin: 'java'
apply plugin: 'org.dm.bundle'

repositories {
    mavenCentral()
}

sourceCompatibility = 1.7
version = '1.0'

Is there a way that I can use the gradle tooling api to find out which plugins this particular gradle project was applying?

I know that you can get the list of project dependencies, but what about the buildscript{} dependencies?

Upvotes: 4

Views: 924

Answers (1)

gamerson
gamerson

Reputation: 5310

This question has actually two separate questions embedded in it. I didn't realize at the time. The first question should be:

1. How do you use the tooling-api to find out of a particular project has applied a particular plugin?

The answer to this question is handled precisely here: Gradle Tooling API Feature

You can find the source code used in that article here: Tooling API Example Repo

However I had some trouble getting that example to build and execute locally so I posted a fix to my own fork if you want to use it.

Then the 2nd question is this:

Once you have the necessary tooling-api model and plugin from question #1, how do you execute this custom tooling script from an Eclipse plugin context?

For this you will need to use the excellent gradle integration plugin for Eclipse as a dependency for your own eclipse plugin. Once this is configured you can simply import these APIs GradleConnector, ProjectConnection, ModelBuilder that are exported by the gradle plugin for eclipse already mentioned.

Getting your own local custom model on the classpath is as easy as embedding the jar in your eclipse plugin as per normal mechanisms (MANIFEST.MF entry, don't forget build.properties to include the jar). Also you will need to have a local repo available for the custom gradle script to pickup the model/plugin classes as show in the example github repo

Upvotes: 1

Related Questions