node-gradle / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
616 stars 120 forks source link

Yarn.cmd not found in 6.0.0 #284

Closed cerbenus closed 1 year ago

cerbenus commented 1 year ago

I'm trying out the just released version 6.0.0 and when executing gradle yarn I get:

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':frontend:yarn'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:149)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:147)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:135)
    at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:74)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
    at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:42)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:337)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:324)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:317)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:303)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:463)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:380)
    at org.gradle.execution.plan.DefaultPlanExecutor.process(DefaultPlanExecutor.java:116)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph.executeWithServices(DefaultTaskExecutionGraph.java:138)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph.execute(DefaultTaskExecutionGraph.java:123)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:35)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:51)
    at org.gradle.execution.BuildOperationFiringBuildWorkerExecutor$ExecuteTasks.call(BuildOperationFiringBuildWorkerExecutor.java:54)
    at org.gradle.execution.BuildOperationFiringBuildWorkerExecutor$ExecuteTasks.call(BuildOperationFiringBuildWorkerExecutor.java:43)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
    at org.gradle.execution.BuildOperationFiringBuildWorkerExecutor.execute(BuildOperationFiringBuildWorkerExecutor.java:40)
    at org.gradle.internal.build.DefaultBuildLifecycleController.lambda$executeTasks$10(DefaultBuildLifecycleController.java:264)
    at org.gradle.internal.model.StateTransitionController.doTransition(StateTransitionController.java:266)
    at org.gradle.internal.model.StateTransitionController.lambda$tryTransition$8(StateTransitionController.java:177)
    at org.gradle.internal.work.DefaultSynchronizer.withLock(DefaultSynchronizer.java:44)
    at org.gradle.internal.model.StateTransitionController.tryTransition(StateTransitionController.java:177)
    at org.gradle.internal.build.DefaultBuildLifecycleController.executeTasks(DefaultBuildLifecycleController.java:255)
    at org.gradle.internal.build.DefaultBuildWorkGraphController$DefaultBuildWorkGraph.runWork(DefaultBuildWorkGraphController.java:220)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:249)
    at org.gradle.internal.work.DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:109)
    at org.gradle.composite.internal.DefaultBuildController.doRun(DefaultBuildController.java:181)
    at org.gradle.composite.internal.DefaultBuildController.access$000(DefaultBuildController.java:50)
    at org.gradle.composite.internal.DefaultBuildController$BuildOpRunnable.run(DefaultBuildController.java:200)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'yarn.cmd''
    at org.gradle.process.internal.DefaultExecHandle.execExceptionFor(DefaultExecHandle.java:241)
    at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:218)
    at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:370)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:87)
    at org.gradle.internal.operations.CurrentBuildOperationPreservingRunnable.run(CurrentBuildOperationPreservingRunnable.java:42)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'yarn.cmd'
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
    at net.rubygrapefruit.platform.internal.WindowsProcessLauncher.start(WindowsProcessLauncher.java:22)
    at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
    at org.gradle.process.internal.ExecHandleRunner.startProcess(ExecHandleRunner.java:98)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:71)
    ... 3 more
Caused by: java.io.IOException: Cannot run program "yarn.cmd" (in directory "leftOutIntentionally\frontend"): CreateProcess error=2, The system cannot find the file specified
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
    ... 7 more
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    ... 8 more

The documentation says:

The plugin never uses a locally-installed yarn because it may be deleted during yarn execution. Instead, it installs yarn into yarnWorkDir (.gradle/yarn/ by default) by the yarnSetup task and use it.

After executing yarnSetup and checking the yarnWorkDir I find a sub folder under "yarn" called "yarn-latest". The yarn.cmd is available but somewhere the referencing must be off...

I do run a Gradle multi module project and therefore use a sub folder called "frontend" from which I'm running these commands.

I have specified my yarnWorkDir as:

// The directory where yarn is installed (when a Yarn task is used) yarnWorkDir = file("${project.projectDir}/.gradle/yarn")

project.projectDir points to sub module.

cerbenus commented 1 year ago

Once I set:

download = true

Yarn started to work as expected.

What am I doing wrong in the globally accessible case (download = false)?

deepy commented 1 year ago

Which version of yarn do you have globally?

This example builds fine for me on Windows

C:\Users\deepy>where yarn
C:\Users\deepy\AppData\Roaming\npm\yarn
C:\Users\deepy\AppData\Roaming\npm\yarn.cmd

C:\Users\deepy>yarn --version
1.22.10
> gradle -p examples/simple-node helloWorld

> Task :yarn:yarnSetup

changed 1 package in 655ms

..

> Task :yarn:yarn
yarn install v1.22.19
warning package.json: No license field
warning example@0.0.0: No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 0.10s.

..

BUILD SUCCESSFUL in 12s
13 actionable tasks: 8 executed, 5 up-to-date

It sounds like there could be a bug with yarnWorkDir, but I couldn't trigger it through the example

deepy commented 1 year ago

My recommendation would be not setting yarnWorkDir and just leave the default setting There is nodeProjectDir if you need to build from elsewhere but the setup I'd recommend is keeping build.gradle(.kts) next to your package.json (or similar)

cerbenus commented 1 year ago

I don't have Yarn installed globally. I thought the plugin downloads Yarn no matter what. Hence, why would I need a global installation?

usage.md states:

The plugin never uses a locally-installed yarn because it may be deleted during yarn execution. Instead, it installs yarn into yarnWorkDir (.gradle/yarn/ by default) by the yarnSetup task and use it.

I'm using:

// Version of Yarn to use // Any Yarn task first installs Yarn in the yarnWorkDir // It uses the specified version if defined and the latest version otherwise (by default) yarnVersion = ""

My build.gradle is next to package.json

deepy commented 1 year ago

I uninstalled the wrong yarn, running completely without yarn this too fails for me and the bug goes basically all the way back. This is conceptually a pretty easy change, though I do worry that it may break someone's workflow around yarn 2/3

But right now we don't have support for yarn 2/3, will debate whether this is a major change or a patch while I have dinner and wait for the tests to pass on CI

deepy commented 1 year ago

@cerbenus this is fixed in 7.0.0 which has now been released

cerbenus commented 1 year ago

I tried 7.0.0. While I can confirm that I don't have a "yarn problem" anymore, I can tell that the .gradle/yarn folder doesn't get created anymore even though the config comment states:

// Any Yarn task first installs Yarn in the yarnWorkDir