Simplify gradleExecutableForCleanup version selection

Use the higher of highestGradleVersion() or MINIMUM_CLEANUP_GRADLE_VERSION.
Remove the separate DEFAULT_CLEANUP_GRADLE_VERSION constant.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Daz DeBoer
2026-04-01 14:30:14 -06:00
parent 09a8521010
commit 8236123cab
+6 -14
View File
@@ -7,7 +7,6 @@ import {BuildResults} from './build-results-adapter'
import {versionIsAtLeast, provisionGradleWithVersionAtLeast} from './gradle-utils' import {versionIsAtLeast, provisionGradleWithVersionAtLeast} from './gradle-utils'
const MINIMUM_CLEANUP_GRADLE_VERSION = '8.11' const MINIMUM_CLEANUP_GRADLE_VERSION = '8.11'
const DEFAULT_CLEANUP_GRADLE_VERSION = '9.4.1'
export class CacheCleaner { export class CacheCleaner {
private readonly gradleUserHome: string private readonly gradleUserHome: string
@@ -37,19 +36,12 @@ export class CacheCleaner {
* This will avoid the need to provision a Gradle version for the cleanup when not necessary. * This will avoid the need to provision a Gradle version for the cleanup when not necessary.
*/ */
private async gradleExecutableForCleanup(buildResults: BuildResults): Promise<string> { private async gradleExecutableForCleanup(buildResults: BuildResults): Promise<string> {
const preferredVersion = buildResults.highestGradleVersion() const highestVersion = buildResults.highestGradleVersion()
if (preferredVersion && versionIsAtLeast(preferredVersion, MINIMUM_CLEANUP_GRADLE_VERSION)) { const version =
try { highestVersion && versionIsAtLeast(highestVersion, MINIMUM_CLEANUP_GRADLE_VERSION)
return await provisionGradleWithVersionAtLeast(preferredVersion) ? highestVersion
} catch (e) { : MINIMUM_CLEANUP_GRADLE_VERSION
core.info( return await provisionGradleWithVersionAtLeast(version)
`Failed to provision Gradle ${preferredVersion} for cache cleanup. Falling back to default version.`
)
}
}
// Fallback to the default version for cache-cleanup
return await provisionGradleWithVersionAtLeast(DEFAULT_CLEANUP_GRADLE_VERSION)
} }
// Visible for testing // Visible for testing