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.
Description
The
UpgradePluginVersionrecipe currently fails to upgrade plugin versions when theapply {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:Expected Behavior
The recipe should upgrade the plugin version regardless of the presence of
apply false:Root Cause
The current implementation in
isPluginVersion()only checks the immediate parent of theversion()method call for theplugins()method. Whenapply falseis present, the chain becomes:The method needs to walk up the entire method invocation chain to find
plugins().Environment
org.openrewrite.gradle.plugins.UpgradePluginVersionProposed Solution
Modify
isPluginVersion()to walk up the method invocation chain until it finds theplugins()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.