Skip to content

UpgradePluginVersion fails to upgrade plugins with 'apply false' #6268

@flex-gwanbin

Description

@flex-gwanbin

Description

The UpgradePluginVersion recipe currently fails to upgrade plugin versions when the apply {boolean} clause is present in the plugin declaration.

Current Behavior

When a Gradle plugin is declared with apply false, the recipe does not detect it as a plugin version that should be upgraded:

// Kotlin DSL - Not upgraded
plugins {
    id("com.github.johnrengelman.shadow") version "7.1.0" apply false
}
// Groovy DSL - Not upgraded
plugins {
    id 'com.github.johnrengelman.shadow' version '7.1.0' apply false
}

Expected Behavior

The recipe should upgrade the plugin version regardless of the presence of apply false:

// Should be upgraded to:
plugins {
    id("com.github.johnrengelman.shadow") version "7.1.2" apply false
}

Root Cause

The current implementation in isPluginVersion() only checks the immediate parent of the version() method call for the plugins() method. When apply false is present, the chain becomes:

plugins() -> ... -> apply() -> version()

The method needs to walk up the entire method invocation chain to find plugins().

Environment

  • OpenRewrite version: main branch (latest)
  • Build tool: Gradle
  • DSL: Both Kotlin DSL and Groovy DSL affected
  • Recipe: org.openrewrite.gradle.plugins.UpgradePluginVersion

Proposed Solution

Modify isPluginVersion() to walk up the method invocation chain until it finds the plugins() method or reaches the root, rather than only checking the immediate parent.

I have a fix ready and will submit a PR shortly with test coverage for both Kotlin DSL and Groovy DSL cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions