Skip to content

Commit

Permalink
Gradle 7.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
chali committed Feb 18, 2021
1 parent 323c256 commit ad6fcc4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class YarnInstallTask

public YarnInstallTask()
{
super(true)
this.group = 'Node'
this.description = 'Install node packages using Yarn.'
setYarnCommand( '' )
Expand Down
33 changes: 26 additions & 7 deletions src/main/groovy/com/moowork/gradle/node/yarn/YarnTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 )
Expand Down

0 comments on commit ad6fcc4

Please sign in to comment.