Skip to content

Conversation

reidbaker
Copy link
Contributor

@reidbaker reidbaker commented Oct 10, 2025

Hold review/merge until #10201 has merged.
This pr is code review feedback from #10201 (comment)

  • Update gradle-check to support minimum java version and validating java version alignment

Pre-Review Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran [the auto-formatter].
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I [linked to at least one issue that this PR fixes] in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy], or I have commented below to indicate which [version change exemption] this PR falls under[^1].
  • I updated CHANGELOG.md to add a description of the change, [following repository CHANGELOG style], or I have commented below to indicate which [CHANGELOG exemption] this PR falls under[^1].
  • I updated/added any relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1].
  • All existing and new tests are passing.

@github-actions github-actions bot added the p: interactive_media_ads Plugin for IMA SDK label Oct 10, 2025
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 updates the Java compatibility version to 17 across multiple Android packages and enhances the gradle-check tool to enforce this new minimum version and ensure version alignment within build.gradle files. The changes also include numerous formatting updates in Dart files, likely from an auto-formatter.

My review focuses on the new validation logic in gradle-check. While the new checks are a great improvement, I've identified a potential issue in how Java versions are parsed, which could lead to incorrect validation in some edge cases. I've provided a suggestion to make the parsing more robust.

Comment on lines +433 to +466
final List<String> javaVersions = <String>[];
// Some java versions have the format VERSION_1_8 but we dont need to handle those
// because they are below the minimum.
final RegExp javaVersionMatcher =
RegExp(r'JavaVersion.VERSION_(?<javaVersion>\d+)');
for (final String line in gradleLines) {
final RegExpMatch? match = javaVersionMatcher.firstMatch(line);
if (!_isCommented(line) && match != null) {
final String? foundVersion = match.namedGroup('javaVersion');
if (foundVersion != null) {
javaVersions.add(foundVersion);
}
}
}
if (javaVersions.isNotEmpty) {
final int version = int.parse(javaVersions.first);
if (version < minimumJavaVersion) {
final String minimumJavaVersionError = '''
build.gradle(.kts) uses "JavaVersion.VERSION_$version".
Which is below the minimum required. Use at least "JavaVersion.VERSION_$minimumJavaVersion".
''';
printError(
'$indentation${minimumJavaVersionError.split('\n').join('\n$indentation')}');
return false;
}
if (!javaVersions.every((String element) => element == '$version')) {
const String javaVersionAlignmentError = '''
If build.gradle(.kts) uses JavaVersion.* versions must be the same.
''';
printError(
'$indentation${javaVersionAlignmentError.split('\n').join('\n$indentation')}');
return false;
}
}

Choose a reason for hiding this comment

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

high

The current logic for parsing Java versions from build.gradle files might not correctly handle older version formats like JavaVersion.VERSION_1_8. The regex RegExp(r'JavaVersion.VERSION_(?<javaVersion>\d+)') only captures numeric versions, so it would miss versions with underscores. This could lead to incorrect validation if a file mixes old and new version formats.

I suggest a more robust parsing logic that can handle both formats (e.g., 11 and 1_8) to ensure all specified Java versions are correctly identified and validated for alignment and minimum version requirements.

    final List<int> javaVersions = <int>[];
    // Some java versions have the format VERSION_1_8.
    final RegExp javaVersionMatcher =
        RegExp(r'JavaVersion.VERSION_(?<javaVersion>[\d_]+)');
    for (final String line in gradleLines) {
      final RegExpMatch? match = javaVersionMatcher.firstMatch(line);
      if (!_isCommented(line) && match != null) {
        final String? foundVersion = match.namedGroup('javaVersion');
        if (foundVersion != null) {
          javaVersions.add(int.parse(foundVersion.split('_').last));
        }
      }
    }
    if (javaVersions.isNotEmpty) {
      final int version = javaVersions.first;
      if (version < minimumJavaVersion) {
        final String minimumJavaVersionError = '''
build.gradle(.kts) uses "JavaVersion.VERSION_$version".
Which is below the minimum required. Use at least "JavaVersion.VERSION_$minimumJavaVersion".
''';
        printError(
            '$indentation${minimumJavaVersionError.split('\n').join('\n$indentation')}');
        return false;
      }
      if (!javaVersions.every((int element) => element == version)) {
        const String javaVersionAlignmentError = '''
If build.gradle(.kts) uses JavaVersion.* versions must be the same.
''';
        printError(
            '$indentation${javaVersionAlignmentError.split('\n').join('\n$indentation')}');
        return false;
      }
    }

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant