Gradle-节点插件':找不到npm命令

时间:2018-07-20 11:31:38

标签: node.js gradle build.gradle gradle-node-plugin

我有一个gradle项目,其中子模块包含js组件。所以我需要安装NodeJS forst,然后咕gr一声,然后进一步构建组件。

下面是我的build.gradle

import org.gradle.api.tasks.Exec
import org.apache.tools.ant.taskdefs.condition.Os


buildscript {
  repositories {
    maven { url "https://plugins.gradle.org/m2/" }
    maven { url "https://xxxxxxxxxx/artifactory/dev" }
    maven { url "http://gasghajksgkag/public" }
    maven { url "http://ashahsha/epository/" }
    maven { url "https://xxxxxxxxxx/artifactory/maven-sasas" }
    maven { url "http://repo.maven.apache.org/maven2" }
  }

  dependencies {
    classpath 'com.moowork.gradle:gradle-node-plugin:0.12'
    classpath "com.moowork.gradle:gradle-grunt-plugin:0.12"
    classpath "com.eriwen:gradle-css-plugin:2.14.0"
    classpath "com.eriwen:gradle-js-plugin:2.14.1"
    classpath 'com.reuters:gradle-fingerprint-plugin:0.3'
    classpath "org.ajoberstar:grgit:2.2.1"
  }
}

ext {
  npmCommand = Os.isFamily(Os.FAMILY_WINDOWS) ? 'npm.cmd' : 'npm'
}

defaultTasks 'createdist'

//command to run this default task gradle createdist --console plain
//else you will get exception Unable to process incoming event 'ProgressComplete ' (ProgressCompleteEvent)
task createdist(dependsOn: ['nodeSetup', 'npmInstallDeps']) {
  println "Initiating building process.........."
}

apply plugin: "com.moowork.node"
apply plugin: 'base'

node {
  version = '8.11.3'
  npmVersion = '5.6.0'
  download = true
  workDir = file("${project.projectDir}/nodejs")
  // distBaseUrl = 'http://nodejs.org/dist'
}

task npmInstallDeps {
  doLast {
    exec {
      commandLine = [npmCommand, "install", "-g", "grunt@~0.4.2"]
    }

    exec {
      commandLine = [npmCommand, "install", "-g", "grunt-contrib-clean"]
    }

    exec {
      commandLine = [npmCommand, "install", "-g", "grunt-cli@~0.1.13"]
    }

    exec {
      commandLine = [npmCommand, "install", "-g", "grunt-replace"]
    }

    exec {
      commandLine = [npmCommand, "install", "-g", "grunt-contrib-copy@~0.8.0"]
    }

    exec {
      commandLine = [npmCommand, "install", "-g", "grunt-contrib-less@~0.8.2"]
    }

    exec {
      commandLine = [npmCommand, "install", "-g", "grunt-contrib-cssmin@~0.12.3"]
    }

    exec {
      commandLine = [npmCommand, "install", "-g", "grunt-contrib-handlebars@~0.7.0"]
    }

    exec {
      commandLine = [npmCommand, "install", "-g", "grunt-contrib-uglify@~0.9.1"]
    }

    exec {
      commandLine = [npmCommand, "install", "-g", "grunt-contrib-concat@~0.5.1"]
    }

    exec {
      commandLine = [npmCommand, "install", "-g", "async@~2.6.1"]
    }

  }
}

tasks.withType(NodeTask) {
  doLast {
    println()
  }
}

task wrapper(type: Wrapper) {
  gradleVersion = '3.2.1'
}

它在父项目中,子模块包含需要通过nodeJS构建的js组件。

现在执行任务时

  

./ gradlew createdist --console = plain

它将在父文件夹内的节点文件夹中下载node.exe。但是无论何时执行npmInstallDeps任务,它都会说:

  

2.045秒内最新:npmInstallDeps失败

     

失败:构建失败,并出现异常。

     
      
  • 出了什么问题:任务':npmInstallDeps'的执行失败。

         
        

    启动进程'命令'npm.cmd'时出现问题

      
  •   
  • 尝试:使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行,以获取更多日志输出。

  •   
     

建立失败

我尝试了许多组合并用Google搜索了一些链接[0],但仍然不知道为什么它不起作用 [0] https://discuss.gradle.org/t/npm-issue-while-running-from-jenkins/25009

0 个答案:

没有答案