Check for Gradle Module Plugin Application

Answered

I'm working on a framework with a gradle plugin.
I've decided that the main way to determine the existence of my framework within a gradle module is to check whether the module applies my Gradle Plugin.

It seems the Android plugin does something similar, when you include  the below code in build.gradle.kts, Android Studio marks the module as a Android Module. I think this is done via a Facet.
plugins {
    id("com.android.application")
}

I would like to do something similar, but for my own gradle plugin.

I've tried looking into the External System, Gradle Plugin, and Android Plugin, but I couldn't find any way to determine whether a plugin is explicitly or transitively (via something like buildSrc gradle projects) included in a gradle module.

Help here would be extremely appreciated. 
Thank you!

0
2 comments

Hi,

Currently, we do not provide a straightforward API for this. You are welcome to request it at https://youtrack.jetbrains.com/issues/IJPL but there are no guarantees about implementation and time.

There are workarounds to this, though:

  1. If the plugin logic could be done on the Gradle's side, you can try implementing ModelBuilder and then work with all the Gradle abstractions directly, but this is possible only during the project model sync. See an example: https://github.com/JetBrains/intellij-community/blob/eda2d1db58ce1868b84c322894c0e54cd5077673/plugins/kotlin/gradle/gradle-tooling/impl/src/org/jetbrains/kotlin/idea/gradleTooling/KotlinGradleModelBuilder.kt#L135 
    It is possible to gather all the required information from the daemon and then use it on the idea's side.
    This approach is used by Android Studio and Kotlin plugin.
  2. If the plugin has an extension, you can get all available extensions via GradleExtensionsSettings.getInstance(project) and then filter the required plugin by fully qualified domain name of the extension class.
1

Hi Karol, thanks so much for this detailed response!

Does Kotlin and Android use this to do Facet Detection? I can't find the implementation on where they detect and apply the Facets.

0

Please sign in to leave a comment.