有没有一种方法可以使gradle项目零配置像这样?

有没有一种方法可以使gradle项目零配置像这样?,gradle,build.gradle,Gradle,Build.gradle,在我的项目中,要求实现“零配置”。这对p.o.来说意味着一个命令配置整个项目,另一个命令启动整个项目。 我在软件开发方面相对较新,尤其是在gradle。 以下是我所做的代码: def frontendDir = "$projectDir/src/main/resources/assets/anwboard-frontend/" task configureProject(type:Exec) { workingDir "$frontendDir" inputs.dir "$fr

在我的项目中,要求实现“零配置”。这对p.o.来说意味着一个命令配置整个项目,另一个命令启动整个项目。 我在软件开发方面相对较新,尤其是在gradle。 以下是我所做的代码:

def frontendDir = "$projectDir/src/main/resources/assets/anwboard-frontend/"
task configureProject(type:Exec) {

    workingDir "$frontendDir"
    inputs.dir "$frontendDir"
    def angularVersion = commandLine "ng", "--version"
    def springbootVersion = commandLine "spring", "version"
    def nodeVersion = commandLine "node", "-v"

    if (nodeVersion == null) {
        if (System.getProperty("os.name").toUpperCase().contains("WINDOWS")) {
            commandLine "choco", "install", "node.jsinstall"
        }else {
            commandLine "brew", "install", "node"
        }
    }

    if (angularVersion == null) {
        if (System.getProperty("os.name").toUpperCase().contains("WINDOWS")) {
                commandLine "npm", "install", "@angular/cli"
        } else {
            commandLine "npm", "install", "angular"
        }
    }

    if (springbootVersion == null) {
        if (System.getProperty("os.name").toUpperCase().contains("WINDOWS")) {
                    commandLine "choco", "install", "spring-boot-cli"
        }else {
                    commandLine "brew", "tap", "pivotal/tap"
                    commandLine "brew", "install", "springboot"
        }
    }
}

task buildAngular(type:Exec) {
    workingDir "$frontendDir"
    inputs.dir "$frontendDir"
        commandLine "ng", "serve", "-o"
}

task buildSpringboot(type:Exec){
    workingDir "$projectDir"
    inputs.dir "$projectDir"
        commandLine "./gradlew", "bootRun"
}
现在警察说“肯定有更好的办法来解决这个问题”,但我不知道,我到处找,但没有结果。 我试图用一个命令启动angular和springboot,但任务从未完成,所以它只启动其中一个。
是否有一种方法可以通过./gradlew build命令以某种方式安装angular、springboot和node.js,或者以其他方式减少必要的命令量?任何帮助都将不胜感激。

可以通过添加并将其用于节点和NPM安装来增强
configureProject
任务(只需使用
npmSetup
任务)。然后可以使用NPM安装Angular CLI,随后可以使用
包.json
脚本运行
ng serve
。最后,这里看起来您没有使用Spring Boot CLI。你确定你需要它吗

如果您对Node/NPM/Angular CLI进行上述更改并删除Spring Boot CLI用法,那么您的配置任务将大大简化

对于运行应用程序来说,Gradle实际上是一个构建工具(或者说是一个任务运行器)的核心。它实际上并不意味着同时为多个应用程序编写执行<代码>引导运行和长时间运行的NPM任务是可能的,但通常每个Gradle实例只能运行其中一个任务,因为Gradle只支持每个项目同时执行一个任务

从技术上讲,可以使用Gradle运行多个应用程序,但是您必须将它们从Gradle进程()中分离出来,或者使用。您应该能够通过worker API将所有要执行的应用程序提交到工作队列,但请记住,这将是一个非常手动的解决方案,不是Gradle的目标,并且会有一些限制。例如,您必须确保有足够的Gradle Worker来运行所需的所有并发应用程序


如果您有多个同时运行的应用程序,那么您可能需要考虑使用其他一些工具。例如,如果您正在通过IntelliJ运行此任务,那么您可以创建一个运行这两个任务的共享复合运行配置。如果你在开发环境之外运行,那么你可以考虑使用DokeCopys.< /P>我输入了任务<代码> /GeLDLW NPMSTATAs/CODE >,但是我得到了错误。“当我尝试执行命令

npm install angular
时,启动进程'command'npm'时出现问题。”。如何修复此问题?抱歉,
npmSetup
任务只是将NPM安装到一个特定于年级的目录中,然后可以将其用于其他NPM任务。后续命令仍需通过Gradle执行。尝试添加一个
package.json
脚本,该脚本执行
ng-serve
(例如,
“开始”:“ng-serve”
)。生成的Gradle任务类似于NPM命令,将空格替换为下划线:
/gradlew NPM\u start