checkGradleVersion method

Future<void> checkGradleVersion()

Check the Gradle version in gradle-wrapper.properties

Implementation

Future<void> checkGradleVersion() async {
  final wrapperPath = FileSystemUtils.findGradleWrapperProperties(androidDir);
  if (wrapperPath == null) {
    issues.add(
      IssueModel(
        filePath: path.join(
          androidDir,
          'gradle/wrapper/gradle-wrapper.properties',
        ),
        description: 'Gradle wrapper properties file not found',
        currentValue: 'Missing',
        recommendedValue: 'Create the file with Gradle $latestGradleVersion',
        isCritical: true,
      ),
    );
    return;
  }

  final content = await FileSystemUtils.readFile(wrapperPath);
  final RegExp gradleVersionRegex = RegExp(
    r'distributionUrl=.*?gradle-([0-9.]+)-',
  );
  final match = gradleVersionRegex.firstMatch(content);

  if (match == null) {
    issues.add(
      IssueModel(
        filePath: wrapperPath,
        description: 'Gradle version not found in properties file',
        currentValue: 'Unknown',
        recommendedValue: latestGradleVersion,
        isCritical: true,
      ),
    );
    return;
  }

  final currentVersion = match.group(1) ?? '';
  if (_isVersionLowerThan(currentVersion, latestGradleVersion)) {
    issues.add(
      IssueModel(
        filePath: wrapperPath,
        description: 'Gradle version is outdated',
        currentValue: currentVersion,
        recommendedValue: latestGradleVersion,
      ),
    );
  }
}