From 3a97a38c41f1e9c9bef59f237cdcab0346ffa55d Mon Sep 17 00:00:00 2001 From: Michael Rittmeister Date: Fri, 28 Jun 2024 19:24:59 +0200 Subject: [PATCH] Add support for type-safe plugin apply (#150958) The Gradle Kotlin DSL also allows for type-safe application of the Flutter Gradle plugin, which is currently undetected by the CLI ```kotlin plugins { dev.flutter.`flutter-gradle-plugin` } ``` Please note that the added test case isn't ideal, since the example gradle isn't actually valid kotlin DSL, however the `kotlin host app language with Gradle Kotlin DSL` is identical Fixes #149859 --- packages/flutter_tools/lib/src/project.dart | 4 +++- .../test/general.shard/project_test.dart | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/project.dart b/packages/flutter_tools/lib/src/project.dart index 7a23614b7f9..fd8a814d0a6 100644 --- a/packages/flutter_tools/lib/src/project.dart +++ b/packages/flutter_tools/lib/src/project.dart @@ -544,7 +544,9 @@ class AndroidProject extends FlutterProjectPlatform { // pluginManagement block of the settings.gradle file. // See https://docs.gradle.org/current/userguide/composite_builds.html#included_plugin_builds, // as well as the settings.gradle and build.gradle templates. - final bool declarativeApply = line.contains('dev.flutter.flutter-gradle-plugin'); + final bool declarativeApply = line.contains( + RegExp(r'dev\.flutter\.(?:(?:flutter-gradle-plugin)|(?:`flutter-gradle-plugin`))'), + ); // This case allows for flutter run/build to work for modules. It does // not guarantee the Flutter Gradle Plugin is applied. diff --git a/packages/flutter_tools/test/general.shard/project_test.dart b/packages/flutter_tools/test/general.shard/project_test.dart index 330128a1961..79de85b2573 100644 --- a/packages/flutter_tools/test/general.shard/project_test.dart +++ b/packages/flutter_tools/test/general.shard/project_test.dart @@ -805,6 +805,28 @@ plugins { id "kotlin-android" id "dev.flutter.flutter-gradle-plugin" } +'''; + }); + expect(project.android.isKotlin, isTrue); + }, overrides: { + FileSystem: () => fs, + ProcessManager: () => FakeProcessManager.any(), + XcodeProjectInterpreter: () => xcodeProjectInterpreter, + FlutterProjectFactory: () => flutterProjectFactory, + }); + + testUsingContext('kotlin host app language with Gradle Kotlin DSL and typesafe plugin id', () async { + final FlutterProject project = await someProject(); + + addAndroidGradleFile(project.directory, + kotlinDsl: true, + gradleFileContent: () { + return ''' +plugins { + id "com.android.application" + id "kotlin-android" + dev.flutter.`flutter-gradle-plugin` +} '''; }); expect(project.android.isKotlin, isTrue);