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
,这似乎使我无所适从,因为我再也无法阻止它在配置阶段执行。理想情况下,我希望它能够在执行阶段或手动调用时执行。
我仍在寻找实现这一目标的方法。