checkKotlinVersion method
Check the Kotlin version in the root build.gradle
Implementation
Future<void> checkKotlinVersion() async {
final buildGradlePath = FileSystemUtils.findRootBuildGradle(androidDir);
if (buildGradlePath == null) {
// We already report this in GradleDoctor, so we don't duplicate the issue
return;
}
final content = await FileSystemUtils.readFile(buildGradlePath);
final RegExp kotlinVersionRegex = RegExp(
'ext\\.kotlin_version\\s*=\\s*["\']([0-9.]+)["\']',
);
final match = kotlinVersionRegex.firstMatch(content);
if (match == null) {
issues.add(
IssueModel(
filePath: buildGradlePath,
description: 'Kotlin version not found in root build.gradle',
currentValue: 'Not defined',
recommendedValue: "ext.kotlin_version = '$latestKotlinVersion'",
),
);
return;
}
final currentVersion = match.group(1) ?? '';
if (_isVersionLowerThan(currentVersion, latestKotlinVersion)) {
issues.add(
IssueModel(
filePath: buildGradlePath,
description: 'Kotlin version is outdated',
currentValue: currentVersion,
recommendedValue: latestKotlinVersion,
),
);
}
}