Skip to content

Conversation

@flex-gwanbin
Copy link

@flex-gwanbin flex-gwanbin commented Nov 7, 2025

Changes

  • Modified isPluginVersion() to walk up the entire method invocation chain to find the plugins() method
  • Previously only checked the immediate parent, which failed when apply false was between version() and plugins()
  • Now correctly handles patterns like: id(...) version "x.y.z" apply false

Testing

Added test coverage for both DSLs:

  • kotlinDslWithApplyFalse: Tests Kotlin DSL with apply false
  • groovyDslWithApplyFalse: Tests Groovy DSL with apply false

Before

plugins {
    id("com.github.johnrengelman.shadow") version "7.1.0" apply false
}

No upgrade happened ❌

After

plugins {
    id("com.github.johnrengelman.shadow") version "7.1.2" apply false
}

Successfully upgraded ✅

Root Cause

The method invocation chain with apply false is:

plugins() → ... → apply() → version()

The previous implementation only checked one level up from version(), finding apply() instead of plugins().

Technical Details

Changed in UpgradePluginVersion.java:116-141:

  • Added a while loop to traverse the method invocation chain
  • Continues until finding plugins() or reaching the root
  • Properly handles intermediate method calls like apply()

The previous implementation only checked the immediate parent of the
version() method call for the plugins() method. This failed when other
method calls (like 'apply false') were chained between version() and
plugins().

This change walks up the entire method invocation chain to find the
plugins() method, correctly handling patterns like:
  id(...) version "x.y.z" apply false

Added test coverage for both Kotlin DSL and Groovy DSL with apply false.
POSIX standard requires text files to end with a newline character.
@timtebeek timtebeek requested a review from shanman190 November 7, 2025 11:23
@timtebeek timtebeek added bug Something isn't working recipe Requested Recipe gradle labels Nov 7, 2025
@shanman190
Copy link
Contributor

This recipe predates several new enhancements, one of which I think could excellently be deployed here and that's the GradlePlugin trait. It understands the apply syntax already as well as a few more syntactic possibilities.

In it's current form, it'd help to find the plugin declaration while also handling several more cases. Furthermore, like we've done with other traits could be updated to handle the basic changes that one may want to apply to a plugin declaration.

If you feel up to this @flex-gwanbin , then I can help coach you through various aspects of the above. Alternatively, if that feels a bit too much Tim or I can jump in and apply this improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working gradle recipe Requested Recipe

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

UpgradePluginVersion fails to upgrade plugins with 'apply false'

3 participants