Skip to content

Commit

Permalink
Use faster D: drive for Gradle User Home on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdaz committed Jul 19, 2024
1 parent b175189 commit f8aa3ed
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion sources/src/setup-gradle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import * as fs from 'fs'
import * as path from 'path'
import * as os from 'os'
import * as caches from './caching/caches'
Expand Down Expand Up @@ -79,7 +80,22 @@ async function determineGradleUserHome(): Promise<string> {
return path.resolve(rootDir, customGradleUserHome)
}

return path.resolve(await determineUserHome(), '.gradle')
const defaultGradleUserHome = path.resolve(await determineUserHome(), '.gradle')
// Use the default Gradle User Home if it already exists
if (fs.existsSync(defaultGradleUserHome)) {
core.info(`Gradle User Home already exists at ${defaultGradleUserHome}`)
return defaultGradleUserHome
}

// Switch Gradle User Home to faster 'D:' drive if possible
if (os.platform() === 'win32' && defaultGradleUserHome.startsWith('C:\\') && fs.existsSync('D:\\a\\')) {
const fasterGradleUserHome = 'D:\\a\\.gradle'
core.info(`Setting GRADLE_USER_HOME to ${fasterGradleUserHome} to leverage (potentially) faster drive.`)
core.exportVariable('GRADLE_USER_HOME', fasterGradleUserHome)
return fasterGradleUserHome
}

return defaultGradleUserHome
}

/**
Expand Down

0 comments on commit f8aa3ed

Please sign in to comment.