I'm working on a Java/Spring Boot Application and like many web applications created with Java and Spring Boot it uses Thymeleaf and Static Resources (CSS, JS, etc). These resources are stored in resources/static/**.

In GitHub Codespaces to see a CSS change I restart the Spring server, not a huge deal but it works with only a slight annoyance. However, if I want to use my local computer instead of GitHub Codespaces I launch up a VS Code Dev Container with the VS Code Remote Containers Extension.

When I update any template or static file the only way to update to take effect is for me to run mvn clean and mvn install to force the entire target/** folder to rebuild. Stopping and starting the server is not enough. The files are not copied to target/**. I've cleared Chrome cache, it's not a caching issue, I even tested with curl just in case. This even happened when I updated application.properties. Which is bad!

This affects any thymeleaf template and static resource. For some reason Maven/Spring does not detect the files have changed. I can confirm that by restarting the application and opening the target/** directory and seeing the file there has not updated. Does VS Code update the last updated timestamp any time you update a CSS file? GitHub Codespaces uses Docker on presumably Linux whereas I run VS Code with Dev Containers on Windows 11.

To work around the issue I defined an application-dev.properties file and updated .vscode/launch.json to append "vmArgs": ["-Dspring.profiles.active=dev"].

In the developer properties I include spring.resources.static-locations=file:src/main/resources/static/ which skips the target directory and need to rebuild. I had to add spring.thymeleaf.cache=false spring.thymeleaf.prefix=file:src/main/resources/templates/ for templates.

This better because you do not need to restart the server for target/** to get updated which works fine in GitHub Codespaces but the new files are not copied to target/** in VS Code with the Remote Containers extension.

An interesting thing about this bug is GitHub Codespaces and VS Code Remote Containers both use Dev Containers (Docker file and stuff is at https://github.com/irlcatgirl/vscode-java-spring-live-reload-config) so it should work in both locations but does not. GitHub Codespaces is in beta and likely has undocumented quirks.

Running mvn install after every template or static file change is unproductive and given it's not needed in GitHub Codespaces I don't understand why it is in VS Code with Dev Containers. My solution (the linked Dockerfile above) resolves the issue in development but why is it necessary in VS Code but not in GitHub Codespaces?

Ignoring the dev tools issue entirely, we still have the issue that target/** is not updating meaning that to build a new JAR I have to run Maven clean and install every time. It also spams the Maven registry with additional unnecessary downloads. This appears to be a bug.

Not effected: - GitHub Codespaces

Effected: - VS Code - Remote Containers (Windows 11)

Needs further testing: - VS Code on Windows 11

Sample Repo I created a sample repo to show the bug. Please compare https://github.com/irlcatgirl/spring-boot-bug-29664-demo/blob/master/src/main/resources/templates/index.html and https://github.com/irlcatgirl/spring-boot-bug-29664-demo/blob/master/target/classes/templates/index.html for further verification of the bug. You can run this demo in any computer with VS Code, Remote Containers Extension, and Docker Desktop.

Comment From: snicoll

@irlcatgirl I am not sure what bug you are referring to. You seem to be aware that, for your template to be picked up by DevTools, they must be updated on the classpath (i.e. copied to target/clases). Everything in your report points to VSCode so I am not sure what you are expecting us to do.

Comment From: elaine-jackson

report

Hi there. The files are indeed copied to target/ the first time (e.g. on the class path). The application would be unable to run (with my current configuration) without that happening. After changing them in src/ the new versions are not picked up and copied over to target/**.

Running some additional tests in another IDE to isolate it to VS Code and/or dev containers.

I mention VS Code because it doesn't seem to happen in other IDEs. Working on a list.

Being I've used mvn clean and install to try and rectify the issue, I'm not sure it's a file system permission issue

Comment From: snicoll

Right ok. If you can reproduce this in more than one ide we can reconsider but that sounds like a vscode specific problem.