Use a properties file to disable daemon execution

Instead of passing `--no-daemon` on the command line, the same
functionality is now acheived by writing a gradle.properties file
when initializing Gradle User Home.
This commit is contained in:
Daz DeBoer 2021-11-27 16:07:07 -07:00
parent 996094e8e8
commit b0c29bffb7
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
3 changed files with 16 additions and 4 deletions

View file

@ -146,7 +146,8 @@ export abstract class AbstractCache {
const cacheResult = await this.restoreCache(this.getCachePath(), cacheKey.key, cacheKey.restoreKeys) const cacheResult = await this.restoreCache(this.getCachePath(), cacheKey.key, cacheKey.restoreKeys)
if (!cacheResult) { if (!cacheResult) {
core.info(`${this.cacheDescription} cache not found. Will start with empty.`) core.info(`${this.cacheDescription} cache not found. Will initialize empty.`)
await this.initializeState()
return return
} }
@ -181,6 +182,8 @@ export abstract class AbstractCache {
} }
} }
protected async initializeState(): Promise<void> {}
protected async afterRestore(_listener: CacheListener): Promise<void> {} protected async afterRestore(_listener: CacheListener): Promise<void> {}
async save(listener: CacheListener): Promise<void> { async save(listener: CacheListener): Promise<void> {

View file

@ -22,6 +22,18 @@ export class GradleUserHomeCache extends AbstractCache {
this.gradleUserHome = this.determineGradleUserHome(rootDir) this.gradleUserHome = this.determineGradleUserHome(rootDir)
} }
async initializeState(): Promise<void> {
this.initializeGradleUserHome(this.gradleUserHome)
}
private initializeGradleUserHome(gradleUserHome: string): void {
fs.mkdirSync(gradleUserHome, {recursive: true})
const propertiesFile = path.resolve(gradleUserHome, 'gradle.properties')
this.debug(`Initializing gradle.properties to disable daemon: ${propertiesFile}`)
fs.writeFileSync(propertiesFile, 'org.gradle.daemon=false')
}
async afterRestore(listener: CacheListener): Promise<void> { async afterRestore(listener: CacheListener): Promise<void> {
await this.reportGradleUserHomeSize('as restored from cache') await this.reportGradleUserHomeSize('as restored from cache')
await this.restoreArtifactBundles(listener) await this.restoreArtifactBundles(listener)

View file

@ -6,9 +6,6 @@ import {writeInitScript} from './build-scan-capture'
export async function execute(executable: string, root: string, args: string[]): Promise<BuildResult> { export async function execute(executable: string, root: string, args: string[]): Promise<BuildResult> {
let buildScanUrl: string | undefined let buildScanUrl: string | undefined
// TODO: instead of running with no-daemon, run `--stop` in post action.
args.push('--no-daemon')
const initScript = writeInitScript() const initScript = writeInitScript()
args.push('--init-script') args.push('--init-script')
args.push(initScript) args.push(initScript)