spring-boot - Spring 启动|在资源文件夹中使用 Intellij 静态和模板运行的替代方案

标签 spring-boot gradle intellij-idea thymeleaf

背景:我们使用 Thymeleaf 和 React 作为前端堆栈来制作 Springboot Web 应用程序。

我们团队当前的流程有两个模块,“客户端”和“服务器”,其中 gradle 命令“clean build”有一个自定义任务,该任务将采用已编译的前端(index.html 和静态 js 和css)并将其适本地放入文件夹中,如下所示:

enter image description here


当您在 Intellij 中运行应用程序时,您可以将项目配置为使用“Gradle”或“Intellij”运行。如下图:

enter image description here

当你使用 gradle 运行时,你实际上不需要复制资源文件夹,而只需将它们放在 ${buildDir} 中。这是默认行为,并且在大多数情况下都有效。如果有人选择了“使用 Intellij 运行”,那么我们需要添加一个额外的复制任务,以将编译后的前端代码放入事件目录中。 (不确定那里的行话)

目标:找到一种运行应用程序的方法,无论您如何运行应用程序,都不需要在静态和模板文件夹中构建资源。

task copyClient(dependsOn: ":client:clientBuild") {
    doLast {
        //For Running with Gradle
        copy {
            from new File(project(":client").getProjectDir(), "build")
            into "${buildDir}/resources/main/static"
        }
        //For Running with Intellij
        copy {
            from new File(project(":client").getProjectDir(), "build/index.html")
            into "src/main/resources/static"
        }
    }
}

最佳答案

您可以将任何 Gradle 任务添加为之前/之后 trigger到 IDE 自己的构建操作:

enter image description here

关于spring-boot - Spring 启动|在资源文件夹中使用 Intellij 静态和模板运行的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65673519/

相关文章:

JQuery 对话框和 Datatable 一起工作

java - 无法将 '' 下的属性绑定(bind)到 com.zaxxer.hikari.HikariDataSource : spring boot 2. 4.1

android - versionNameSuffix用于产品口味

java - 单击按钮即可显示文件选择器。 Java Swing

java - 部署 Spring Boot Fat jar

java - Spring 数据 Neo4j + Kotlin 上的日期转换器

java - Intellij - 错误 :java: invalid source release: 1. 8

java - Intellij 中的 Cassandra 插件

android - 每次gradle同步后找不到Android SDK

spring - 在springboot中使用gradle时,加载依赖项遇到sun.security.validator.validatorexception。我不知道怎么解决