Skip to content

fix: move plugin variable lookups to rootProject.hasProperty - #51

Merged
andredestro merged 1 commit into
mainfrom
fix/RMET-5591/gradle-implicit-property-lookup
Nov 20, 2026
Merged

andredestro merged 1 commit into
mainfrom
fix/RMET-5591/gradle-implicit-property-lookup

Conversation

@andredestro

Copy link
Copy Markdown
Contributor

Description

The migration now moves the plugin's variable lookups from project.hasProperty('x') ? rootProject.ext.x to rootProject.hasProperty('x') ? rootProject.ext.x.

On Gradle 9.8, project.hasProperty() in a plugin only finds x by falling back to the app's root project. Gradle deprecated that ("Implicit lookup of properties in parent projects ... will fail with an error in Gradle 10"), so every app that sets the variable in variables.gradle gets a warning for each migrated plugin. The value is already read from rootProject, so the behavior is the same. Capacitor, the official plugins and the plugin template make the same change (ionic-team/capacitor#8731, ionic-team/capacitor-plugins#2640, ionic-team/create-capacitor-plugin#157).

updateBuildGradle turns these lookups back into the project form right after reading the file, and into the rootProject form right before writing it. The existing matchers (version bumps, kotlin_version and targetSdkVersion removal) look for project.hasProperty, so without the first step a second run on an already migrated file would stop bumping versions. The regex only matches the x ... rootProject.ext.x pattern with the same name on both sides, so other hasProperty() calls in the plugin are left alone.

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation
  • Other (CI, chores, etc.)

Rationale / Problems Fixed

https://outsystemsrd.atlassian.net/browse/RMET-5591
https://docs.gradle.org/9.8.2/userguide/upgrading_version_9.html#deprecated_implicit_lookup_in_parent_projects

Tests

src/property-lookup.test.ts: legacy to rootProject (single and double quotes, string and numeric defaults), idempotent, back to project, and other hasProperty() calls untouched. npm test (44 tests), npm run lint and npm run build pass.

End to end, on a Kotlin plugin generated by create-capacitor-plugin for Capacitor 8:

Run Result
1st Lookups moved to rootProject, versions bumped, kotlin_version, kotlin-android and targetSdkVersion removed, AGP 9.4.1
2nd No changes
3rd, after setting older versions back in the rootProject form Versions bumped again, same output as the 1st run

The migrated plugin in a Capacitor 9 app (Gradle 9.8.2, assembleDebug --warning-mode all) builds with no implicit lookup warnings, and an init script confirmed it picks up the app's variables.gradle values.

Platforms Affected

  • Android
  • iOS
  • Web

Gradle 9 deprecates project.hasProperty() finding a property that is only
declared on the root project, and Gradle 10 will turn it into an error.
Migrated plugins read app overrides with
project.hasProperty('x') ? rootProject.ext.x : default, so apps get a
warning per variable.

Write the lookups as rootProject.hasProperty(). The existing matchers expect
the project form, so updateBuildGradle normalizes to it after reading and
switches to rootProject before writing, which keeps a second run working.
@andredestro
andredestro merged commit a8e7731 into main Nov 20, 2026
1 check passed
@andredestro
andredestro deleted the fix/RMET-5591/gradle-implicit-property-lookup branch November 20, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants