Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Make migrator update gradle wrapper files #5910

Merged
merged 4 commits into from
Sep 14, 2022
Merged
Changes from all commits
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
41 changes: 39 additions & 2 deletions cli/src/tasks/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const plugins = [
];
const coreVersion = '^4.0.0';
const pluginVersion = '^4.0.0';
const gradleVersion = '7.4.2';

export async function migrateCommand(config: Config): Promise<void> {
if (config === null) {
Expand Down Expand Up @@ -246,7 +247,7 @@ export async function migrateCommand(config: Config): Promise<void> {

// Update gradle-wrapper.properties
await runTask(
`Migrating gradle-wrapper.properties by updating gradle version from 7.0 to 7.4.2.`,
`Migrating gradle-wrapper.properties by updating gradle version from 7.0 to ${gradleVersion}.`,
() => {
return updateGradleWrapper(
join(
Expand Down Expand Up @@ -348,6 +349,24 @@ export async function migrateCommand(config: Config): Promise<void> {
return getCommandOutput('npx', ['cap', 'sync']);
});

try {
await runTask(`Upgrading gradle wrapper files`, () => {
return updateGradleWrapperFiles(config.android.platformDirAbs);
});
} catch (e) {
if (e.includes('EACCES')) {
logger.error(
`gradlew file does not have executable permissions. This can happen if the Android platform was added on a Windows machine. Please run ${c.input(
`chmod +x ./${config.android.platformDir}/gradlew`,
)} and ${c.input(
`cd ${config.android.platformDir} && ./gradlew wrapper --distribution-type all --gradle-version ${gradleVersion} --warning-mode all`,
)} to update the files manually`,
);
} else {
logger.error(`gradle wrapper files were not updated`);
}
}

// Write all breaking changes
await runTask(`Writing breaking changes.`, () => {
return writeBreakingChanges();
Expand Down Expand Up @@ -661,11 +680,29 @@ async function updateGradleWrapper(filename: string) {
'distributionUrl=',
'\n',
// eslint-disable-next-line no-useless-escape
`https\\://services.gradle.org/distributions/gradle-7.4.2-all.zip`,
`https\\://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip`,
);
writeFileSync(filename, replaced, 'utf-8');
}

async function updateGradleWrapperFiles(platformDir: string) {
await runCommand(
`./gradlew`,
[
'wrapper',
'--distribution-type',
'all',
'--gradle-version',
gradleVersion,
'--warning-mode',
'all',
],
{
cwd: platformDir,
},
);
}

async function updateFile(
config: Config,
filename: string,
Expand Down