Gradle" ...发生了启动过程'命令 ''''在Mac上

时间:2015-11-05 14:12:09

标签: node.js macos intellij-idea gradle

我安装了IntelliJ Idea的MacOS。我使用Gradle(gradle-2.4)来构建项目。我在Mac上安装了NodeJS和NPM,可从shell获得。

MacBook:~ user$ node -v
v4.2.2
MacBook:~ user$ npm -v
2.14.7

运行使用NODE / NPM的Gradle任务时,它会因以下错误而失败(在当前示例中为NPM)。

* What went wrong:
Execution failed for task ':module:task'.
> A problem occurred starting process 'command 'npm''

Gradle的错误堆栈跟踪如下。

Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':module:task'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
    at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:43)
    at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:30)
    at org.gradle.tooling.internal.provider.ConfiguringBuildAction.run(ConfiguringBuildAction.java:119)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:47)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:35)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:70)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.java:39)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:46)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'npm''
    at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:196)
    at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:325)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:83)
    ... 1 more
Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'npm'
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
    at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:65)
    ... 1 more
Caused by: java.io.IOException: Cannot run program "npm" (in directory "/<project path>"): error=2, No such file or directory
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
    ... 3 more
Caused by: java.io.IOException: error=2, No such file or directory
    ... 4 more

所以看起来Gradle试图在项目绝对目录中找到NPM并且不使用Mac PATH环境变量。任何人都知道如何避免/解决这个问题?我不能使用NODE / NPM的绝对路径,因为团队共享并使用不同的操作系统(Linux,MacOS)。有任何想法吗? :)

7 个答案:

答案 0 :(得分:51)

我通过运行

来停止gradle守护程序
$ ./gradlew --stop

重新运行gradle命令并修复它。

答案 1 :(得分:11)

我有一个类似的问题,在我的情况下,问题是当我从IntelliJ运行它时,Gradle无法访问路径以找出node / npm的位置。我正在使用gradle-gulp-plugin并启用节点的自动下载解决了这个问题。

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath('be.filipblondeel.gradle:gradle-gulp-plugin:0.1')
    }
}
node {
    // Version of node to use.
    version = '0.12.0'

    // Enabled the automatic download.
    download = true
}

答案 2 :(得分:4)

可能对某人有用:

在我的情况下问题是,我运行了Android Studio。 不得不先退出,然后一切都恢复正常。

答案 3 :(得分:3)

我遇到了同样的问题,并通过运行命令解决了问题:

gradle --stop

答案 4 :(得分:0)

我遇到了同样的问题,尝试运行Gradle任务,从Intellij的Gradle插件执行node和npm等命令。您可以从堆栈跟踪中看到Gradle插件正在尝试执行外部系统命令,并且它会收到如下错误:

WARN - nal.AbstractExternalSystemTask - error=2, No such file or directory 
com.intellij.openapi.externalSystem.model.ExternalSystemException: error=2, No such file or directory
at org.jetbrains.plugins.gradle.service.project.GradleExecutionHelper.execute(GradleExecutionHelper.java:228)

如果从路径中删除可执行文件(即node,npm),则可以从命令行重现此错误,这告诉我插件的某些内容不符合环境路径。

我的Gradle插件正在使用项目gradlew(gradle wrapper版本2.3),所以我试图将插件指向我系统上更新的Gradle安装(版本2.10)并且它有效。

然后我通过为我的项目重新生成gradle包装器然后将IntelliJ Gradle插件设置为指向我的包装器来解决我的问题。

我不知道最初的问题是什么。

答案 5 :(得分:0)

答案是,事实证明这是微不足道的。解决方案适用于任何应用程序。

错误的原因是Mac OS X上的所有可视应用都没有使用用户shell,因此当您启动Studio时,~/.bash_profile等本地配置文件设置中的任何内容都无法使用。有一个很好的解决方法:

  1. 从终端,转到此目录或安装Studio应用程序(或任何其他应用程序)的位置:
  2. cd /Applications/Android Studio.app/Contents/MacOS
    
    1. 将工作室可执行文件移动到studio_app(或任何可执行文件名称)
    2. mv $executable$ $executable$_app
      
      1. 创建一个新文本文件,将其命名为$executable$,然后像这样填充它。我在这里使用bash_profile
      2. #!/bin/sh    
        . ~/.bash_profile
        logger "`dirname \"$0\"`/$executable$_app"
        exec "`dirname \"$0\"`/$executable$_app" $@
        
        1. 关闭工作室文件。来自shell更改权限:
        2. chmod +x $executable$
          

          就是这样。通常重新启动Studio应用程序,现在它继承了bash_profile的所有设置,包括节点的路径等。

          用您的exe文件名替换$executable$。对于Android Studio,它只是工作室。对于IntelliJ,它应该只是intellij(仔细检查)。

答案 6 :(得分:0)

可能有帮助:

  

sudo launchctl config用户路径$ PATH

&#34;要生效,可能需要重启机器&#34;