[tool] Add initial non-plugin package support for Kotlin Gradle#11127
[tool] Add initial non-plugin package support for Kotlin Gradle#11127stuartmorgan-g wants to merge 6 commits intoflutter:mainfrom
Conversation
|
version/chaneglog override: modernizing the example build files is not relevant to clients. |
|
Assuming this looks good, I can do a follow-up PR to repeat this for all the other non-plugin examples (which are presumably all simple), and then we can tackle plugins one at a time (updating the tooling further when we do the first one). |
There was a problem hiding this comment.
Code Review
This pull request introduces initial support for validating non-plugin packages that use Kotlin Gradle files (.gradle.kts) in the gradle-check tool. This is achieved by updating the tool to recognize .kts files and apply specific validation logic for the Kotlin DSL. As a test case, the animations example's Android project is migrated from Groovy to Kotlin Gradle files. The changes include updating build logic, namespaces, and dependencies to conform to Kotlin DSL syntax and modern Gradle practices. The validation tool's tests are also expanded to cover these new Kotlin-based scenarios.
| // Returns the gradle file in the given directory. | ||
| File _getBuildGradleFile(Directory dir) => dir.childFile('build.gradle'); | ||
| File _getBuildGradleFile(Directory dir) { | ||
| const buildGradleBaseName = 'build.gradle'; | ||
| const buildGradleKtsBaseName = '$buildGradleBaseName.kts'; | ||
| if (dir.childFile(buildGradleKtsBaseName).existsSync()) { | ||
| return dir.childFile(buildGradleKtsBaseName); | ||
| } | ||
| return dir.childFile(buildGradleBaseName); | ||
| } | ||
|
|
||
| // Returns the settings gradle file in the given directory. | ||
| File _getSettingsGradleFile(Directory dir) => | ||
| dir.childFile('settings.gradle'); | ||
| File _getSettingsGradleFile(Directory dir) { | ||
| const settingsGradleBaseName = 'settings.gradle'; | ||
| const settingsGradleKtsBaseName = '$settingsGradleBaseName.kts'; | ||
| if (dir.childFile(settingsGradleKtsBaseName).existsSync()) { | ||
| return dir.childFile(settingsGradleKtsBaseName); | ||
| } | ||
| return dir.childFile(settingsGradleBaseName); | ||
| } |
There was a problem hiding this comment.
To reduce code duplication, the logic for finding a .gradle or .gradle.kts file could be extracted into a shared helper function.
// Returns a Gradle file in the given directory, preferring .kts if it exists.
File _getGradleFile(Directory dir, String baseName) {
final File ktsFile = dir.childFile('$baseName.kts');
if (ktsFile.existsSync()) {
return ktsFile;
}
return dir.childFile(baseName);
}
// Returns the gradle file in the given directory.
File _getBuildGradleFile(Directory dir) => _getGradleFile(dir, 'build.gradle');
// Returns the settings gradle file in the given directory.
File _getSettingsGradleFile(Directory dir) =>
_getGradleFile(dir, 'settings.gradle');There was a problem hiding this comment.
🤷🏻
I didn't worry much about optimal structure in any of these changes since once we convert everything over we'll rip out all the non-Kotlin paths.
| println("Using artifact hub") | ||
| maven { | ||
| url = uri(artifactRepoUrl) | ||
| } |
There was a problem hiding this comment.
This conversion from Groovy was done by Gemini. It recommended the get-and-null-check pattern rather than a direct conversion of the check-for-key-then-read Groovy code, because this is null safe rather than requiring a force unwrap. That seemed entirely reasonable to me.
The uri part I trusted it on 🤷🏻
| @@ -1,2 +1,2 @@ | |||
| org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError | |||
| org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError | |||
There was a problem hiding this comment.
I didn't see any reason not to just adopt the current template defaults here.
This adds support for non-plugin Gradle validation of packages that use Kotlin Gradle files rather than Groovy gradle files. More work will need to be done to be able to validate plugins that use Kotlin Gradle files, but this is enough for just Android apps.
As a test case for this new validation, this also migrates the
animationsexample app to Kotlin Gradle. Rather than doing a manual migration, this was done by:example android/directorystableandroid/.pluginToolsConfig.yaml(without changes)Part of flutter/flutter#176065
Pre-Review Checklist
[shared_preferences]///).Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2