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-node-plugin无法找到类型command
的npmInstallPkg
的属性NpxTask
,这是在配置任务本身时期望的。对我有用的唯一解决方案是删除doLast
块。
但是似乎无法在command
中定义doLast
似乎使我无所适从,因为我再也无法阻止它在配置阶段执行。理想情况下,我希望它能够在执行阶段或手动调用时执行。
尽管这解决了我原来的问题,但我仍在寻找一种在执行阶段调用任务的方法。
关于gradle - 没有为gradle节点插件 'command'属性指定值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62251999/