【问题标题】:No value has been specified for property 'command', gradle node plugin没有为属性“命令”指定值,gradle 节点插件
【发布时间】:2020-06-18 06:12:56
【问题描述】:
task  npmInstallPkg(type: NpxTask){
    doLast{
        //install node packages from package.json
        dependsOn npmInstall

        //install pkg globally
        command = 'npm'
        args = ['install', '-g', 'pkg']
    }
}

每当我尝试执行上述任务时,都会出现以下错误:

A problem was found with the configuration of task ':npmInstallPkg'.
> No value has been specified for property 'command'.

我正在使用 "com.github.node-gradle.node" 插件版本 "2.2.4"

我多次交叉检查了语法,但没有发现任何问题。 我通过引用https://github.com/node-gradle/gradle-node-plugin/blob/2.2.4/docs/node.md#executing-npm-commands-via-npx的插件文档来创建任务

我的节点配置块如下:

// gradle node plugin configuration
node {
  // Version of node to use.
  version = '10.14.1'

  // Version of npm to use.
  npmVersion = '6.4.1'

  // Version of Yarn to use.
  yarnVersion = '1.3.2'

  // Base URL for fetching node distributions (change if you have a mirror).
  distBaseUrl = 'https://nodejs.org/dist'

  // If true, it will download node using above parameters.
  // If false, it will try to use globally installed node.
  download = true

  // Set the work directory for unpacking node
  workDir = file("${project.buildDir}/nodejs")

  // Set the work directory for NPM
  npmWorkDir = file("${project.buildDir}/npm")

  // Set the work directory for Yarn
  yarnWorkDir = file("${project.buildDir}/yarn")

  // Set the work directory where node_modules should be located
  nodeModulesDir = file("${project.projectDir}")
}

【问题讨论】:

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


    【解决方案1】:

    似乎该错误是因为 gradle-node-plugin 无法找到 npmInstallPkg 类型为 NpxTask 的属性 command,这是它在配置任务本身时所期望的。唯一对我有用的解决方案是删除 doLast 块。

    但无法在doLast 中定义command 似乎消除了我的负担,因为我无法在配置阶段阻止它执行。理想情况下,我希望它能够在执行阶段或手动调用它时执行。

    虽然这解决了我最初的问题,但我仍在寻找一种在执行阶段调用任务的方法。

    【讨论】:

      猜你喜欢
      • 2014-08-20
      • 1970-01-01
      • 1970-01-01
      • 2019-09-25
      • 2015-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多