from Hacker News

Show HN: Gradle plugin for faster Java compiles

by sgammon on 6/3/25, 7:59 PM with 33 comments

Hey HN,

We've written a pretty cool Gradle plugin I wanted to share.

It turns out if you native-image the Java and Kotlin compilers, you can experience a serious gain, especially for "smaller" projects (under 10,000 classes).

By compiling the compiler with native image, JIT warmup normally experienced by Gradle/Maven et al is skipped. Startup time is extremely fast, since native image seals the heap into the binary itself. The native version of javac produces identical outputs from inputs. It's the same exact code, just AOT-compiled, translated to machine code, and pre-optimized by GraalVM.

Of course, native image isn't optimal in all cases. Warm JIT still outperforms NI, but I think most projects never hit fully warmed JIT through Gradle or Maven, because the VM running the compiler so rarely survives for long enough.

Elide (the tool used by this plugin) also supports fetching Maven dependencies. When active, it prepares a local m2 root where Gradle can find your dependencies already on-disk when it needs them. Preliminary benchmarking shows a 100x+ gain since lockfiles prevent needless re-resolution and native-imaging the resolver results in a similar gain to the compiler.

We (the authors) are very much open to feedback in improving this Gradle plugin or the underlying toolchain. Please, let us know what you think!

  • by pjmlp on 6/4/25, 9:49 AM

    Personally the solution to faster build times in Gradle, is to keep using Maven.

    I never touch Gradle unless there is no way around it, like Android.

    However, this looks like an interesting idea.

  • by jart on 6/3/25, 10:08 PM

    OK let's say I have an online store I wrote in Spring Framework. What does my before and after development workflow look like after adopting your plugin? It's been a while since I've messed with Java, but how many seconds could it possibly need to fetch a bunch of jar files? I'd love to see an in-the-life-of kind of screencast of what the daily grind looks like for normal java devs these days, so I can understand why it's so slow.

    For example, what does resolution mean? Does that mean fetching the pom.xml files from sonatype to figure out the dependency graph? Don't those HTTP requests normally go fast? Is Elide sort of like setting up an HTTP caching proxy between corp and sonatype?

  • by alisonatwork on 6/3/25, 11:43 PM

    Hypothetically, if you could daemonize javac, would JIT eventually kick in over multiple recompiles of the same code? The obvious use case for this would be IDEs, but I imagine it could work in CI too if you had some kind of persistent "compiler as a service" setup that outlived the runners.

    Not to detract from the cool work done here, just curious if this other approach has been tried too.

  • by sgammon on 6/3/25, 11:05 PM

    Volker Simonis over at Amazon did some very cool benchmarks showing the impact this can have (i.e. native-imaging javac):

    https://github.com/simonis/LeydenVsGraalNative

  • by kristianp on 6/3/25, 11:59 PM

    So elide is a tool to run {js|ts|py} [1]. How does it compile javac to native?

    [1] https://github.com/elide-dev/elide

  • by linksbro on 6/4/25, 1:31 AM

    Would this result in the same .class that javac produces? I.e. at runtime is code compiled with this fundamentally different than code compiled with javac?
  • by re-thc on 6/4/25, 3:02 AM

    Interesting idea. I wonder how this would compare to native-imaging Gradle or Maven itself.
  • by lemming on 6/4/25, 10:00 AM

    The underlying Elide tool looks amazing, and potentially solves all sorts of pain for me. Does the Kotlin compiler support plugins, e.g. serialisation? I can imagine they might be too reflective.
  • by normie3000 on 6/4/25, 6:05 AM

    Is there an equivalent maven plugin?

    Also what's the licence for elide?

  • by Zardoz84 on 6/4/25, 7:09 AM

    interesting. I wonder how compares against mavend (mvnd , aka maven as a Daemon service) and his aggressive parallelization.
  • by rjwalters on 6/4/25, 6:10 AM

    Do you have benchmarks? How much of a difference does it make?