Skip to content
Alessandro Autiero
Go back

Dev server - Hot reload for Maven and Gradle builds

We discussed this feature on Reddit

In short, what we want to implement with this PR is a dev-server that performs hot reload, similar to quarkus mvn quarkus:dev. I implemented this as Maven/Gradle plugins: the reason is that, as the dev-server needs to compile the project, it should integrate with the user’s existing build infrastructure.

What the Maven/Gradle plugins do is:

  1. Compile the project
  2. Collect all sources/resources that should be watched and start a service that watches them on a separate thread
  3. Look for a main method(supports JEP 512) using ASM
  4. Set a dev port System property that the application will use instead of the app port
  5. Start the application on the dev port with some classloader magic to make sure the application stays isolated
  6. Wait for the application to start and get the app port
  7. Start a TCP socket on the dev port

(This explanation is obviously very high level, there is a lot of complexity involved in doing some of these things, especially arbitrarly compiling the project whenever we want in a multi threaded environment)

When a request arrives on our TCP socket, we check if the file watcher thread has updates: if there are no updates then we simply forward the request to the app server, otherwise we recompile, start the new app and then finally forward the request we got to the new server. This is thread safe and there is a debounce logic in place so we don’t have to check too often if code changed, but HTTP 1.1+ and WebSockets support keep alives which makes things slightly more complicated because we can’t just kill the old server: the policy I went for is to keep the old backend running until all connections are closed. This means that the old backend won’t get the updated code, but i think this is the right behaviour considering the nature of keep alives. It could be a good idea to have a maximum amount of servers we allow to run concurrently so we don’t cause resource exhaustion: I haven’t implemented that yet. I have already written the E2E test for Maven, not Gradle, but haven’t pushed them yet because I wanted to collect some feedback first on the implementation. Keep in mind that there are a lot of edge cases, mostly related to:

  1. Multi module setups
  2. Annotation processors that do codegen(e.g. immutables) or modify compiler internals(i.g. lombok)
  3. Compiler plugins

I also haven’t wrote javadocs yet, I think it’s not needed because this is an internal module, but let me know what your policy on this is.

I also understand it’s a lot of code for a PR, and that it will need to be reviewed and tested carefully, let me know if you have any questions about why I made some choices/if something is not clear

Btw I’m using a TCP socket for the proxy so we don’t have to handle parsing and resending data, we can just forward it. Problem is, it looks like there isn’t a no-copy pipe system from a SocketChannel(the proxy’s) to another(the app’s) so I currently allocate a direct bytebufer: if this is actually the best approach, it would make sense to create some sort of pool as they are expensive to allocate. This is likely a Java NIO limitation though, I’d bet Netty has a way to implement this without allocating additional buffers.

Also I’m not using Virtual Threads because that requires Java 19 :/


Originally opened as a GitHub pull request, javalin/javalin#2542, on February 27, 2026.



Previous Post
PEXT/PDEP intrinsics cause a performance regression on AMD pre-Zen 3 CPUs
Next Post
[SILOptimizer] Don't treat a borrowed addressable argument as escaping for the purpose of write effects