gpt4 book ai didi

gradle - Gradle无法正确执行外部命令

转载 作者:行者123 更新时间:2023-12-03 05:20:16 32 4
gpt4 key购买 nike

我有以下gradle任务,可使用npm构建前端代码:

task buildFrontend() {
doLast {
exec {
workingDir "src/ui"
commandLine "npm", "install"
commandLine "npm", "run", "build"
}
...
}
但是,当我运行构建时,出现以下错误:
...
> Task :solutions:dash:buildFrontend FAILED

...
> ng build --base-href /p/ --prod

sh: 1: ng: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! dash@0.0.0 build: `ng build --base-href /p/ --prod`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the dash@0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
...

FAILURE: Build failed with an exception.
...

* What went wrong:
Execution failed for task ':solutions:dash:buildFrontend'.
> Process 'command 'npm'' finished with non-zero exit value 1
...
但是,当我 cdsrc/ui目录并从终端运行 npm install,然后重新运行gradle构建时,它将成功。
似乎Gradle无法执行 commandLine "npm", "install"的方式和结果与我从终端手动执行的方式相同。
但为什么?这两个命令-gradle build和manual npm install由同一用户从终端执行...

最佳答案

exec块分成两部分后,如下所示:

exec {
workingDir "src/ui"
commandLine "npm", "install"
}
exec {
workingDir "src/ui"
commandLine "npm", "run", "build"
}
该应用程序的构建没有错误。

关于gradle - Gradle无法正确执行外部命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63806504/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com