-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
Use case
Since 3.22, Flutter supports writing Gradle buildscripts in Kotlin, in addition to Groovy.
Using Kotlin instead of Groovy in Gradle buildscripts has many advantages and has been recommended by Gradle since April 2023 (link).
I think it makes sense to make Kotlin the default language, to bring those advantages to every Flutter developer, many of whom are understandably not experts in Gradle, Groovy, and their quirks.
Proposal
Scope:
- Change the language of files in Gradle templates from Groovy to Kotlin
- Revise existing documentation on flutter/website to make sure it works equally well for both Groovy and Kotlin templates.
As for bullet point (2), it's worth noting that in many cases, Kotlin syntax in Gradle is a subset of Groovy syntax, so we in many cases we can just show Kotlin syntax and it'll work the same in Groovy, e.g.:
Example 1
This works only in Groovy:
dependencies {
implementation "com.example:my-artifact:1.2.3"
}but the following works both in Groovy and in Kotlin:
dependencies {
implementation("com.example:my-artifact:1.2.3")
}Example 2
This works only in Groovy:
android {
namespace "pl.baftek.discoverrudy"
compileSdk 34
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget "11"
}
defaultConfig {
applicationId "pl.baftek.discoverrudy"
minSdk 23
targetSdk 34
versionCode flutter.versionCode()
versionName flutter.versionName()
}
}but this works in both:
android {
namespace = "pl.baftek.discoverrudy"
compileSdk = 34
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
defaultConfig {
applicationId = "pl.baftek.discoverrudy"
minSdk = 23
targetSdk = 34
versionCode = flutter.versionCode()
versionName = flutter.versionName()
}
}Alternatively, we might decide to provide users with a switch when calling flutter create, e.g. flutter create --android-build-language kotlin and flutter create --android-build-language groovy.