Spingboot | Alternative to running with Intellij static and templates in resource folder

Viewed 53

Background: We make Springboot web applications with Thymeleaf and React as the front end stack.

Our team's current process, is having two modules, 'client' and 'server' where on the gradle command "clean build" to have a custom task that will take the complied front end (index.html and the static js and css) and put it appropriately in the folders as you can see here:

enter image description here


When you run an application in Intellij, you can configure the project to either run with 'Gradle' or 'Intellij'. As shown below:

enter image description here

When you run with gradle, you do not actually need to copy the resources folder but instead just put them in the ${buildDir}. This is the default behavior and works great the majority of the time. If someone has 'run with Intellij' selected, then we need to add an additional copy task to have the compiled front end code into the active directory. (Not sure of the lingo there)

Goal: Find a way to run application where you do not need to have built recourses in static and templates folder no matter how you run application.

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"
        }
    }
}
1 Answers

You can add any Gradle task as Before/After trigger to the IDE's own Build action:

enter image description here

Related