Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Format toolig
  • Loading branch information
reidbaker committed Oct 9, 2025
commit 33dbb858e015103668188da10d14ed3f28f4011f
18 changes: 13 additions & 5 deletions script/tool/lib/src/gradle_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,18 @@ build.gradle "namespace" must match the "package" attribute in AndroidManifest.x
final bool hasLanguageVersion = gradleLines.any((String line) =>
line.contains('languageVersion') && !_isCommented(line));
final bool hasCompabilityVersions = gradleLines.any((String line) =>
line.contains('sourceCompatibility = JavaVersion.VERSION_$requiredJavaVersion') && !_isCommented(line)) &&
line.contains(
'sourceCompatibility = JavaVersion.VERSION_$requiredJavaVersion') &&
!_isCommented(line)) &&
// Newer toolchains default targetCompatibility to the same value as
// sourceCompatibility, but older toolchains require it to be set
// explicitly. The exact version cutoff (and of which piece of the
// toolchain; likely AGP) is unknown; for context see
// https://github.com/flutter/flutter/issues/125482
gradleLines.any((String line) =>
line.contains('targetCompatibility = JavaVersion.VERSION_$requiredJavaVersion') && !_isCommented(line));
line.contains(
'targetCompatibility = JavaVersion.VERSION_$requiredJavaVersion') &&
!_isCommented(line));
if (!hasLanguageVersion && !hasCompabilityVersions) {
const String javaErrorMessage = '''
build.gradle(.kts) must set an explicit Java compatibility version.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should say "must set an explicit Java compatibility version of $requiredJavaVersion."

With the updated check, someone who adds an incorrect compatibility version will get an error message that just says that they need to set an explicit version, which they did, so it will be confusing.

Expand Down Expand Up @@ -395,7 +399,8 @@ for more details.''';
'$indentation${javaErrorMessage.split('\n').join('\n$indentation')}');
return false;
}
bool isKotlinOptions(String line) => line.contains('kotlinOptions') && !_isCommented(line);
bool isKotlinOptions(String line) =>
line.contains('kotlinOptions') && !_isCommented(line);
final bool hasKotlinOptions = gradleLines.any(isKotlinOptions);
final bool kotlinOptionsUsesJavaVersion = gradleLines.any((String line) =>
line.contains('jvmTarget = JavaVersion.VERSION_$requiredJavaVersion') &&
Expand All @@ -404,8 +409,11 @@ for more details.''';
if (hasKotlinOptions && !kotlinOptionsUsesJavaVersion) {
// Bad lines contains the first 4 lines including the kotlinOptions section.
String badLines = '';
final int startIndex = gradleLines.indexOf(gradleLines.firstWhere(isKotlinOptions));
for(int i = startIndex; i < math.min(startIndex + 4, gradleLines.length); i++) {
final int startIndex =
gradleLines.indexOf(gradleLines.firstWhere(isKotlinOptions));
for (int i = startIndex;
i < math.min(startIndex + 4, gradleLines.length);
i++) {
badLines += '${gradleLines[i]}\n';
}
final String kotlinErrorMessage = '''
Expand Down