Gradle Task-无法设置Path变量,execCommand == null1

时间:2018-07-23 10:03:21

标签: gradle build build.gradle

下面是我的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 "http://repo.maven.apache.org/maven2" }
  }

  dependencies {
    classpath 'com.moowork.gradle:gradle-node-plugin:1.2.0'
    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'
  //execPath = "$System.env.PATH" + System.getProperty("path.separator") + "${project.projectDir}/nodejs/*"
  execPath = "$System.env.PATH"
}

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', 'seNodeP']) {
  println execPath
  println "Initiating building process.........."
}

task setNodePathVar {
  doLast {
    new File("${project.projectDir}/nodejs/").eachDir {
      execPath += System.getProperty("path.separator") + it
    }

    println "Complete pathList:" + execPath
  }
}

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

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

task seNodeP (dependsOn: 'setNodePathVar') {
  exec {
    environment "PATH", execPath
  }
}

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

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

clean {
  delete "target"
}

执行./gradlew createdist后出现以下错误:

  

$。/ gradlew createdist c:\ Users \ user_name \ bin;。; C:\ Program   Files \ Git \ local \ bin; C:\ Program Files \ Git \ mingw \ bin; C:\ Program   Files \ Git \ bin; c:\ Program   文件\ Docker \ Docker \ Resources \ bin; c:\ ProgramData \ Oracle \ Java \ javapath; c:\ WINDOWS \ system32; c:\ WINDOWS; c:\ WINDOWS \ System32 \ Wbem; c:\ WINDOWS \ System32 \ WindowsPowerShell \ v1.0 \; c:\ Program   档案   (x86)\ Sennheiser \ SoftphoneSDK \; c:\ apache-maven-3.3.9 \ bin; c:\ Users \ user_name \ AppData \ Local \ Microsoft \ WindowsApps; c:\ Program   Files \ Docker Toolbox; c:\ work \ analytic-components \ nodejs启动   构建过程..........

     

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

     
      
  • 其中:构建文件'C:\ work \ analytic-components \ build.gradle'行:63

  •   
  • 出了什么问题:评估根项目“分析组件”时出现问题。

         
        

    execCommand ==空!

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

  •   
     

建立失败

     

总时间:1.296秒

为什么我要获得execCommand == null! 在上述任务中,首先我要在本地下载NodeJS,然后将路径添加到PATH变量。

0 个答案:

没有答案