Skip to content

Migrate Gradle plugin to Kotlin, away from Groovy #121541

@gnprice

Description

@gnprice

The Android Gradle Plugin team, when asked about the recurring flake #103230, said (per #103230 (comment)):

it looks like a bug in Groovy's dynamic dispatch. If you invoke the method from something statically compiled (Java or Kotlin) you should be fine (or even just use @CompileStatic if you don't want to convert)

For context, we got rid of all groovy production code in AGP many years ago for performance and correctness reasons

That sounds like a pretty clear recommendation that everyone else should do the same: migrate any production code written in Groovy (with the .gradle filename extension) either to Java, or to Kotlin (with .gradle.kts). When the AGP team did that migration "many years ago", Kotlin was young and the Gradle Kotlin DSL didn't exist, so they went for Java, but today the right choice is almost certainly Kotlin.

For Flutter, this means the files in packages/flutter_tools/gradle/, in particular flutter.gradle. These total about 1600 lines of code. An initial step was taken in #114660, moving a small piece of logic to a new flutter.gradle.kts.

Docs from Gradle upstream, on the Gradle Kotlin DSL (of .gradle.kts files) and on migrating to it:
https://docs.gradle.org/current/userguide/kotlin_dsl.html
https://docs.gradle.org/current/userguide/migrating_from_groovy_to_kotlin_dsl.html

This isn't urgent, and I don't think there's any need for it to be an immediate priority. Filing this so there's a clean issue to track it.

Non-goals

A possible future step would be to migrate the build.gradle files generated by flutter create to be Kotlin files build.gradle.kts too. Then along with that, one should try to help migrate the build.gradle files in existing Flutter projects. These may also be good things to do, but can be left out of scope for this issue.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityc: performanceRelates to speed or footprint issues (see "perf:" labels)r: fixedIssue is closed as already fixed in a newer versiont: gradle"flutter build" and "flutter run" on Androidteam-androidOwned by Android platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-androidTriaged by Android platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions