diff --git a/lib/manager/gradle-wrapper/artifacts.spec.ts b/lib/manager/gradle-wrapper/artifacts.spec.ts index 359bbf60dafa0f2534a0b656a977e9c87e34caad..1a3b5266d777316397d3df68a32ff5449a63044c 100644 --- a/lib/manager/gradle-wrapper/artifacts.spec.ts +++ b/lib/manager/gradle-wrapper/artifacts.spec.ts @@ -86,10 +86,14 @@ describe(getName(__filename), () => { 'gradlew.bat', ].forEach((file) => { expect( - readFileSync(resolve(__dirname, `./__fixtures__/testFiles/${file}`)) + readFileSync( + resolve(__dirname, `./__fixtures__/testFiles/${file}`), + 'utf8' + ) ).toEqual( readFileSync( - resolve(__dirname, `./__fixtures__/expectedFiles/${file}`) + resolve(__dirname, `./__fixtures__/expectedFiles/${file}`), + 'utf8' ) ); }); diff --git a/lib/manager/gradle-wrapper/artifacts.ts b/lib/manager/gradle-wrapper/artifacts.ts index e4e619801fce5c6afda3534a468a091fb86fab29..bb7193aa0b9402f00af2a16b411f6967fde4b2b8 100644 --- a/lib/manager/gradle-wrapper/artifacts.ts +++ b/lib/manager/gradle-wrapper/artifacts.ts @@ -24,8 +24,21 @@ async function addIfUpdated( return null; } +function getDistributionUrl(newPackageFileContent: string): string { + const distributionUrlLine = newPackageFileContent + .split('\n') + .find((line) => line.startsWith('distributionUrl=')); + if (distributionUrlLine) { + return distributionUrlLine + .replace('distributionUrl=', '') + .replace('https\\:', 'https:'); + } + return null; +} + export async function updateArtifacts({ packageFileName, + newPackageFileContent, updatedDeps, config, }: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> { @@ -34,12 +47,18 @@ export async function updateArtifacts({ logger.debug({ updatedDeps }, 'gradle-wrapper.updateArtifacts()'); const gradlew = gradleWrapperFileName(config); const gradlewPath = resolve(projectDir, `./${gradlew}`); - const cmd = await prepareGradleCommand( + let cmd = await prepareGradleCommand( gradlew, projectDir, await fs.stat(gradlewPath).catch(() => null), - `wrapper --gradle-version ${config.toVersion}` + `wrapper` ); + const distributionUrl = getDistributionUrl(newPackageFileContent); + if (distributionUrl) { + cmd += ` --gradle-distribution-url ${distributionUrl}`; + } else { + cmd += ` --gradle-version ${config.toVersion}`; + } logger.debug(`Updating gradle wrapper: "${cmd}"`); const execOptions: ExecOptions = { docker: {