When developing a Java project in VSCode, it can be quite inconvenient when Spring reload does not occur after an automatic build. To address this issue, Gradle continuous is commonly used.
Terminal 1
gradle build -t
Terminal 2
gradle bootRun
While Terminal 1 only needs to be started once, doing it every time is inconvenient. One solution to this problem is to use the compounds feature in VSCode's launch. compounds allow multiple launch configurations to be executed as a single unit.
Solution
{
"version": "0.2.0",
"configurations": [
{
"name": "Spring Boot-BaseApplication",
"type": "java",
"request": "launch",
"cwd": "${workspaceFolder}",
"mainClass": "kr.co.findthebest.Application",
"projectName": "workspace",
"args": "",
"envFile": "${workspaceFolder}/.env",
"encoding": "UTF-8"
},
{
"name": "Run gradle continuous",
"type": "node-terminal",
"command": "gradle build --warning-mode=all -t --parallel --build-cache --configuration-cache",
"request": "launch",
"cwd": "${workspaceFolder}"
}
],
"compounds": [
{
"name": "Auto build",
"configurations": [
"Run gradle start",
"Spring Boot-BaseApplication"
],
"stopAll": true
}
]
}
By modifying the
launch.jsonas above, you can create acompoundsnamed "Auto build."Running this
compoundswill execute "Run gradle continuous" and "Spring Boot-BaseApplication" sequentially.
This approach eliminates the need to start each terminal individually, streamlining the process.
Another method involves adding a task to use the preLaunchTask feature in launch. However, due to less smooth background pattern matching, this method may reduce the risk of failure in certain situations.
Conclusion
When developing a Java project in VSCode and aiming for automatic build and Spring reload, using compounds is an effective solution.
By adopting this method, you can simplify the workflow, reducing cumbersome tasks.
Top comments (0)