From ad6fcc4718c34eebb039c72b269c334cd9d9bd2d Mon Sep 17 00:00:00 2001 From: Martin Chalupa Date: Thu, 18 Feb 2021 12:46:47 -0800 Subject: [PATCH] Gradle 7.0 compatibility --- .../gradle/node/yarn/YarnInstallTask.groovy | 1 + .../moowork/gradle/node/yarn/YarnTask.groovy | 33 +++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/groovy/com/moowork/gradle/node/yarn/YarnInstallTask.groovy b/src/main/groovy/com/moowork/gradle/node/yarn/YarnInstallTask.groovy index 239aeaa..9f14209 100644 --- a/src/main/groovy/com/moowork/gradle/node/yarn/YarnInstallTask.groovy +++ b/src/main/groovy/com/moowork/gradle/node/yarn/YarnInstallTask.groovy @@ -16,6 +16,7 @@ class YarnInstallTask public YarnInstallTask() { + super(true) this.group = 'Node' this.description = 'Install node packages using Yarn.' setYarnCommand( '' ) diff --git a/src/main/groovy/com/moowork/gradle/node/yarn/YarnTask.groovy b/src/main/groovy/com/moowork/gradle/node/yarn/YarnTask.groovy index bf0a6dc..b71dcb7 100644 --- a/src/main/groovy/com/moowork/gradle/node/yarn/YarnTask.groovy +++ b/src/main/groovy/com/moowork/gradle/node/yarn/YarnTask.groovy @@ -5,6 +5,8 @@ import org.gradle.api.tasks.Internal import org.gradle.api.tasks.TaskAction import org.gradle.process.ExecResult +import javax.inject.Inject + class YarnTask extends DefaultTask { @@ -16,23 +18,40 @@ class YarnTask private String[] yarnCommand - public YarnTask() + @Inject + public YarnTask() { + this(false) + } + + public YarnTask(boolean afterEvaluateConfiguration) { this.runner = new YarnExecRunner( this.project ) dependsOn( YarnSetupTask.NAME ) - this.project.afterEvaluate { - if ( !this.runner.workingDir ) - { + def initWorkDir = { + if (!this.runner.workingDir) { def workingDir = this.project.node.nodeModulesDir - setWorkingDir( workingDir ) + setWorkingDir(workingDir) } - if ( !this.runner.workingDir.exists() ) - { + if (!this.runner.workingDir.exists()) { this.runner.workingDir.mkdirs(); } } + + //This class is used from different contexts. + //1) it is a parent for a usually created task - in that case we need to initialize + // working directory after evaluation so we can capture customizations + //2) task created by a rule. In that case we are already after evaluation and we don't need to + // wait with configuration. Gradle 7+ actually fails if you invoke after evaluate + // if a project is past that phase + if (afterEvaluateConfiguration) { + this.project.afterEvaluate { + initWorkDir() + } + } else { + initWorkDir() + } } void setArgs( final Iterable value )