Skip to content

[tool] Add initial non-plugin package support for Kotlin Gradle#11127

Open
stuartmorgan-g wants to merge 6 commits intoflutter:mainfrom
stuartmorgan-g:android-example-refresh-part-i-initial-non-plugin
Open

[tool] Add initial non-plugin package support for Kotlin Gradle#11127
stuartmorgan-g wants to merge 6 commits intoflutter:mainfrom
stuartmorgan-g:android-example-refresh-part-i-initial-non-plugin

Conversation

@stuartmorgan-g
Copy link
Collaborator

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 animations example app to Kotlin Gradle. Rather than doing a manual migration, this was done by:

  • Deleting the entire example android/ directory
  • Recreating it on stable
  • Restoring android/.pluginToolsConfig.yaml (without changes)
  • Adding a Kotlin version of the Artifact Hub configuration
  • Removing the TODO comments that are part of the template Gradle files

Part of flutter/flutter#176065

Pre-Review Checklist

Footnotes

  1. 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

@stuartmorgan-g stuartmorgan-g added override: no versioning needed Override the check requiring version bumps for most changes override: no changelog needed Override the check requiring CHANGELOG updates for most changes labels Feb 26, 2026
@github-actions github-actions bot added p: animations platform-android triage-framework Should be looked at in framework triage labels Feb 26, 2026
@stuartmorgan-g
Copy link
Collaborator Author

version/chaneglog override: modernizing the example build files is not relevant to clients.

@stuartmorgan-g
Copy link
Collaborator Author

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).

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 103 to +121
// 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);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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');

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷🏻

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)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see any reason not to just adopt the current template defaults here.

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

Labels

override: no changelog needed Override the check requiring CHANGELOG updates for most changes override: no versioning needed Override the check requiring version bumps for most changes p: animations platform-android triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant