Skip to content

Commit b4b5532

Browse files
chore(cli): Migrate task updates kotlin version in root build.gradle (#8238)
1 parent e8507cf commit b4b5532

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cli/src/tasks/migrate.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const coreVersion = 'next';
4747
const pluginVersion = 'next';
4848
const gradleVersion = '8.14.3';
4949
const iOSVersion = '15';
50+
const kotlinVersion = '2.2.20';
5051
let installFailed = false;
5152

5253
export async function migrateCommand(config: Config, noprompt: boolean, packagemanager: string): Promise<void> {
@@ -489,9 +490,26 @@ async function updateBuildGradle(
489490
}
490491
}
491492
}
493+
494+
const beforeKotlinVersionUpdate = replaced;
495+
replaced = replaceVersion(replaced, /(ext\.kotlin_version\s*=\s*['"])([^'"]+)(['"])/, kotlinVersion);
496+
replaced = replaceVersion(replaced, /(org\.jetbrains\.kotlin:kotlin[^:]*:)([\d.]+)(['"])/, kotlinVersion);
497+
if (beforeKotlinVersionUpdate !== replaced) {
498+
logger.info(`Set Kotlin version to ${kotlinVersion}`);
499+
}
492500
writeFileSync(filename, replaced, 'utf-8');
493501
}
494502

503+
function replaceVersion(text: string, regex: RegExp, newVersion: string): string {
504+
return text.replace(regex, (match, prefix, currentVersion, suffix) => {
505+
const semVer = coerce(currentVersion)?.version;
506+
if (gte(newVersion, semVer ? semVer : '0.0.0')) {
507+
return `${prefix || ''}${newVersion}${suffix || ''}`;
508+
}
509+
return match;
510+
});
511+
}
512+
495513
async function updateAppBuildGradle(filename: string) {
496514
const txt = readFile(filename);
497515
if (!txt) {

0 commit comments

Comments
 (0)