我不知道这个构建gradle脚本有什么问题

问题描述 投票:0回答:1

我真的不知道是什么问题。 我想要的是,当项目构建时,它的工作方式就像输入命令“npm install”。 这个错误发生在构建时。 请帮助我。

这是错误消息。

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':web:npmInstall'.
> A problem occurred starting process 'command 'npm''

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s
6 actionable tasks: 6 executed
5:37:28: Task execution finished 'build'.

这是 build.gradle.kts 文件。

plugins {
    id("com.moowork.node") version "1.3.1"
    id("com.github.node-gradle.node") version "2.2.3"
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
    implementation("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.1.0")
    developmentOnly("org.springframework.boot:spring-boot-devtools")

    implementation(project(":domain"))
    implementation(project(":common"))
}

tasks.getByName("bootJar"){
    enabled = false
}
tasks.getByName("jar"){
    enabled = true
}

buildscript {
    repositories {
        maven {
            url = uri("https://plugins.gradle.org/m2/")
        }
        gradlePluginPortal()
    }
    dependencies {
        classpath("com.moowork.gradle:gradle-node-plugin:1.3.1")
        classpath("com.github.node-gradle:gradle-node-plugin:2.2.3")
    }
}

apply(plugin = "com.moowork.node")
apply(plugin = "com.github.node-gradle.node")

configure<com.moowork.gradle.node.NodeExtension> {
    version = "21.1.0"
    npmVersion = "10.2.0"
    isDownload = true
    workDir = file("C:/Program Files/nodejs")
    npmWorkDir = file("C:/Program Files/nodejs")
    nodeModulesDir = project.file("${projectDir}/src/main/resources/static")
}

val npmInstall by tasks.getting(com.moowork.gradle.node.npm.NpmTask::class) {
    dependsOn.clear()
    doLast {
        exec {
            commandLine("npm", "install")
        }
    }
}

val copyFrontLib by tasks.registering(Copy::class) {
    from("${projectDir}/src/main/resources/static")
    into("${projectDir}/build/resources/main/static/.")
    dependsOn(npmInstall)
}

tasks.getByName("compileJava").dependsOn(copyFrontLib)

我无法理解问题所在。 所以我对这个问题无能为力。 请帮助我。

gradle build
1个回答
0
投票

您的构建脚本预计可以在命令行中运行

npm
命令。

这也是 Node Gradle 插件 (docs) 的先决条件。

因此,请在您的系统上安装 npm 和/或确保该命令可用,然后重试。

© www.soinside.com 2019 - 2024. All rights reserved.