-
Notifications
You must be signed in to change notification settings - Fork 28.8k
Add support for Gradle Kotlin DSL #140744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Gradle Kotlin DSL #140744
Conversation
0259f18
to
41f3efc
Compare
packages/flutter_tools/test/integration.shard/android_plugin_skip_unsupported_test.dart
Outdated
Show resolved
Hide resolved
ced7840
to
9ee9337
Compare
9ee9337
to
2e1a505
Compare
2e1a505
to
7e48577
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks really good. My biggest concerns are related. One is about files being ignored currently that we start reading that could/would cause a build failure. The second is about users that are migrating to kotlin and how we can support them having some build.gradle and some build.gradle.kts code at the same time.
return buildGradle.exists() || buildGradleKts.exists() | ||
} | ||
|
||
private File settingsGradleFile() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider a doc on this function that says we prefer the settings.gradle.kts over settings.gradle.
Also I think this might cause an issue for customers updating since they could have a settings.gradle.kts file that is being ignored and maybe is malformed and a flutter update would cause their build to break. Let me talk this over with @christopherfujino and the android team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the doc comment.
Re: your concern – it is possible that a situation like that might happen, but I think this would be very rare case. Of course I have no data to back it up - I'm according to my experience and "gut feeling". Like, why would some developer end up with both settings.gradle.kts
and settings.gradle
?
Personally I wouldn't care about it (with my current state of knowledge).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry but we have competing guts, I think it is likely to happen for customers who are mid migration and they wont realize that there are different behaviors. Unlike build.gradle and build.gradle.kts I dont think settings.gradle and settings.gradle.kts are mutually exclusive.
Either way our code should be clear on what we expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I get you. Thanks for competing with my gut.
I tested Gradle's behavior when both settings.gradle.kts
and settings.gradle
exist:
build.gradle.kts
rootProject.name = "gradle-example-kts"
logger.quiet("Hello, the project name is: ${rootProject.name}")
build.gradle
rootProject.name = "gradle-example"
logger.quiet("Hello, the project name is: ${rootProject.name}")
Gradle completely ignores settings.gradle.kts
:
$ gradle projects
Hello, the project name is: gradle-example
> Task :projects
------------------------------------------------------------
Root project 'gradle-example'
------------------------------------------------------------
Root project 'gradle-example'
No sub-projects
To see a list of the tasks of a project, run gradle <project-path>:tasks
For example, try running gradle :tasks
BUILD SUCCESSFUL in 391ms
1 actionable task: 1 executed
So I think we should follow Gradle's behavior (use Groovy even when Kotlin exists). I'd also print a warning (using logger.error()
) since this seems unintuitive to me).
Tested on Gradle 8.5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same thing happens for build.gradle.kts
and build.gradle
:
build.gradle.kts
tasks.register("hello-kotlin") {
group = "fun"
description = "Says hello from Kotlin"
doLast {
logger.quiet("Hello from Gradle KTS")
}
}
build.gradle
tasks.register("hello-groovy") {
group = "fun"
description = "Says hello from Groovy"
doLast {
logger.quiet("Hello from Gradle Groovy")
}
}
Running (some irrelevant output omitted):
$ gradle tasks
Fun tasks
---------
hello-groovy - Says hello from Groovy
Tested on Gradle 8.5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for testing, It does make sense that we would try to mirror gradles default behavior and I do think this is good evidence that we DO NOT prefer the kotlin file over the groovy file. I do think that a hard failure could still make sense but I think I have asked you to churn on this enough and we can change the behavior later if we made the wrong call.
@@ -204,20 +204,28 @@ distributionUrl=https\\://services.gradle.org/distributions/gradle-$gradleVersio | |||
/// The Android plugin version is specified in the [build.gradle] file within | |||
/// the project's Android directory. | |||
String getGradleVersionForAndroidPlugin(Directory directory, Logger logger) { | |||
final File buildFile = directory.childFile('build.gradle'); | |||
const String buildFileName = 'build.gradle/build.gradle.kts'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think either this variable should be removed and the logger strings below should have this inline or the logger strings should stay the same using the file object and rely on the if statement below to use set buildfile
correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went for a variable because that string occured in 3 logger.printTrace()
statements and remembered rule-of-3.
I'll go with this:
the logger strings should stay the same using the file object and rely on the if statement below to use set buildfile correctly
I would also add logger.error()
so that users who (for whatever weird reason) don't have a build.gradle
/build.gradle.kts
file will see red text when flutter build
ing. Should this case even be supported? I doubt flutter app build works without these buildfiles.
Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote some of this code originally and I it is more likely that we have a bug in our code than that the users code does not match the conditions below.
Specifically the regular expressions assume a groovy style syntax. Can you file an issue and put it in a comment here that this code needs to be updated with regular expressions and tests that cover the kotlin case in addition to groovy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed #141410 can you add a reference to that bug in this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean specifically the _buildAndroidGradlePluginRegExp
RegExp that is used in this method (getGradleVersionForAndroidPlugin()
), then it works in both Groovy and Kotlin.
File get appGradleFile => hostAppGradleRoot.childDirectory('app') | ||
.childFile('build.gradle'); | ||
/// | ||
/// It can be written in Groovy (build.gradle) or Kotlin (build.gradle.kts). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include in the dart doc the behavior if both build.gradle and build.gradle.kts are present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in d30b4da
32ff639
to
150f8cf
Compare
// found in the LICENSE file. | ||
|
||
// This file is currently NOT auto generated. | ||
// DO NOT update it by running by dev/tools/bin/generate_gradle_lockfiles.dart. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a confusing comment. running that script won't update this anyway, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or will it, and is the user supposed to run that script then revert the change to this file? If so, I would recommend we update the script instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or will it, and is the user supposed to run that script then revert the change to this file?
That's right.
I created #140115 because changing the generate_gradle_lockfiles.dart
script and running it is a quite massive change (see that PR's "lines changed"). That's why this comment exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that case lets make the comment something closer to "This file is auto updated by dev/tools/bin/generate_gradle_lockfiles.dart, do not merge changes to this file. See #140115"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in 90c07d3
I talked to the android team and here is what they said
I am trying to find documentation for what gradle does if you have both build.gradle and build.gradle.kts. I believe it errors. If I cant find documentation then I will just try it and update here. I think we should lean towards mirroring the behavior of gradle, The flutter android team thinks we should stop and error out or have a configuration option and default behavior (which I understand is significantly more work to land the pr). |
I agree. I think that doing sth like |
f249659
to
6b83e98
Compare
…oth Groovy and Kotlin
This reverts commit 5e863e6.
flutter/flutter@9f2e681...7dc856a 2024-01-12 36861262+QuncCccccc@users.noreply.github.com Revert "Reverts "Run iOS staging tests with Xcode 15.2"" (flutter/flutter#141420) 2024-01-12 engine-flutter-autoroll@skia.org Roll Packages from 0744fe6 to d74d687 (5 revisions) (flutter/flutter#141449) 2024-01-12 tessertaha@gmail.com Fix `FlexibleSpaceBar` centered title position and title color (flutter/flutter#140883) 2024-01-12 whesse@google.com Do not reset framework checkout before running customer tests (flutter/flutter#141013) 2024-01-12 43054281+camsim99@users.noreply.github.com Increase delay for checking integration_ui_keyboard_resize test success (flutter/flutter#141301) 2024-01-12 godofredoc@google.com Add osx_sdk context for mac builds. (flutter/flutter#141422) 2024-01-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from ecdaed76f284 to 44a0a6ee4d39 (18 revisions) (flutter/flutter#141432) 2024-01-12 barpac02@gmail.com Add support for Gradle Kotlin DSL (flutter/flutter#140744) 2024-01-12 36861262+QuncCccccc@users.noreply.github.com Fix typo (flutter/flutter#141426) 2024-01-11 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Run iOS staging tests with Xcode 15.2" (flutter/flutter#141412) 2024-01-11 15619084+vashworth@users.noreply.github.com Run iOS staging tests with Xcode 15.2 (flutter/flutter#141392) 2024-01-11 tessertaha@gmail.com Fix `ListWheelScrollView` in an `AnimatedContainer` with zero height throw an error (flutter/flutter#141372) 2024-01-11 andrewrkolos@gmail.com make asset_test.dart tests not dependent on context (flutter/flutter#141331) 2024-01-11 57464965+Macacoazul01@users.noreply.github.com Expose 'enable' property to allow the user to disable the SearchBar (flutter/flutter#137388) 2024-01-11 jonahwilliams@google.com Add impeller key to skia gold client, Turn on a framework test shard that will run unit tests with --enable-impeller (flutter/flutter#141341) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC camillesimon@google.com,rmistry@google.com,stuartmorgan@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…relevant to legacy plugins
…142464) This reverts commit f5ac225, i.e. #137115. This is a continuation of #142266 that was redone based on feedback to make this easier to revert in the future. The exact steps I took to create this revert: 1. Revert commit noted above 2. Fix merge conflicts, that notably involved reverting some changes in #140744 ~and #141417 (fixed my merge to avoid the second PR from being affected) 3. Delete `packages/flutter_tools/test/integration.shard/android_plugin_skip_unsupported_test.dart` as this was added in the commit noted above cc @Gustl22 since I couldn't tag as a reviewer
)" (flutter#142464) This reverts commit f5ac225, i.e. flutter#137115. This is a continuation of flutter#142266 that was redone based on feedback to make this easier to revert in the future. The exact steps I took to create this revert: 1. Revert commit noted above 2. Fix merge conflicts, that notably involved reverting some changes in flutter#140744 ~and flutter#141417 (fixed my merge to avoid the second PR from being affected) 3. Delete `packages/flutter_tools/test/integration.shard/android_plugin_skip_unsupported_test.dart` as this was added in the commit noted above cc @Gustl22 since I couldn't tag as a reviewer
* master: (45 commits) Reverts "Update gradle lockfiles template" (flutter#142889) Update gradle lockfiles template (flutter#140115) Roll Flutter Engine from 20742e37e54e to f34c658b9600 (1 revision) (flutter#142876) Roll Flutter Engine from 23763db72272 to 20742e37e54e (1 revision) (flutter#142850) Roll Flutter Engine from fee02145da8c to 23763db72272 (3 revisions) (flutter#142848) Roll Flutter Engine from 9869d47a2736 to fee02145da8c (2 revisions) (flutter#142847) Roll Flutter Engine from 78c63d3c2c68 to 9869d47a2736 (1 revision) (flutter#142842) Roll Flutter Engine from 266d5d0b5588 to 78c63d3c2c68 (1 revision) (flutter#142836) Bump github/codeql-action from 3.23.2 to 3.24.0 (flutter#142839) Bump codecov/codecov-action from 3.1.6 to 4.0.1 (flutter#142838) Update TextSelectionOverlay (flutter#142463) Roll Flutter Engine from e29263212bfd to 266d5d0b5588 (5 revisions) (flutter#142832) Fix CupertinoTextSelectionToolbar clipping (flutter#138195) Reland "Add support for Gradle Kotlin DSL (flutter#140744)" (flutter#142752) Support navigation during a Cupertino back gesture (flutter#142248) Avoid depending on files from build_system/targets other than from top level entrypoints in flutter_tools. (flutter#142760) Roll Packages from 5b48c44 to d37fb0a (14 revisions) (flutter#142812) Add a link the different possible Android virtual device configs (flutter#142765) Allow all iOS tests to use either iOS 16 or 17 (flutter#142714) Roll Flutter Engine from b35153d00b2e to e29263212bfd (2 revisions) (flutter#142799) ...
This PR resolves #140548. It's based on my work in #118067.
Pre-launch Checklist
///
).