diff options
author | Philippe Perrin <philippe.perrin@sonarsource.com> | 2021-09-24 17:23:00 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-09-28 20:03:12 +0000 |
commit | da28abee08e06eb2c4220304aa7771f92371b048 (patch) | |
tree | f46db75b185ba280c86419d0febee090d669a47f /build.gradle | |
parent | 5a3c534591e01f75ee82a0ccc0d4219bcce61167 (diff) | |
download | sonarqube-da28abee08e06eb2c4220304aa7771f92371b048.tar.gz sonarqube-da28abee08e06eb2c4220304aa7771f92371b048.zip |
Avoid unnecessary yarn install runs
Diffstat (limited to 'build.gradle')
-rw-r--r-- | build.gradle | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/build.gradle b/build.gradle index 4c67c8dd4d8..6c4d916ca5d 100644 --- a/build.gradle +++ b/build.gradle @@ -666,3 +666,36 @@ dependencyUpdates { rejected } } + +// Hack to avoid unecessary yarn install. +// This will create a avoidInstallTask task on which both installTask & runTask will depend. +// installTask is disabled and will only be activated by avoidInstallTask when it is executed +// Because it is set to share the same dependencies, avoidInstallTask will be executed only if +// the runTask will be executed +ext.avoidYarnInstallIfPossible = { taskList, installTask, runTask -> + // Disable the yarn install task + installTask.enabled = false; + + def avoidInstallTask = taskList.register('avoidInstallTask_' + runTask.name) { + // Copy all inputs and outputs + runTask.inputs.getFiles().each { fi -> + if (fi.isDirectory()) inputs.dir(fi) + else inputs.file(fi) + } + runTask.outputs.getFiles().each { fi -> + if (fi.isDirectory()) outputs.dir(fi) + else outputs.file(fi) + } + + outputs.cacheIf { true } + + // Activate the yarn install task + doLast { + installTask.enabled = true + } + } + + runTask.dependsOn(installTask) + runTask.dependsOn(avoidInstallTask) + installTask.dependsOn(avoidInstallTask) +}
\ No newline at end of file |