Back to Intellij Community

AvoidApplyPluginMethod

plugins/gradle/resources/inspectionDescriptions/AvoidApplyPluginMethod.html

2025.3-rc-21.0 KB
Original Source

Detects usage of legacy apply plugin methods in Gradle build scripts.

If the plugin is a core plugin, or it comes from the gradlePluginPortal, offers a quick-fix to convert the legacy syntax to the preferred plugins block syntax. The buildscript block will be automatically modified to remove redundant dependencies, and in the case it becomes empty, it will be removed as well.

Core Plugin example:

apply(plugin = "java") // highlights this line

After the quick-fix is applied:

plugins {
    id("java")
}

External Plugin example:

buildscript {
    repositories {
        gradlePluginPortal()
    }

    dependencies {
        classpath("com.google.protobuf:com.google.protobuf.gradle.plugin:0.9.4")
    }
}

apply(plugin = "com.google.protobuf") // reports this line

After the quick-fix is applied:

plugins {
    id("com.google.protobuf").version("0.9.4")
}

Best practice described here.