Home United States USA — software Faster Maven Builds in Docker

Faster Maven Builds in Docker

86
0
SHARE

Learn how to run faster Maven builds inside Docker containers using BuildKit, layers, volume mounts, and by tweaking the Maven daemon.
Join the DZone community and get the full member experience. Last week, I described different techniques to quicken your Maven builds. Today, I’d like to widen the scope and do the same for Maven builds inside Docker. Between each run, we change the source code by adding a single blank line; between each section, we remove all built images, including the intermediate ones that are the results of the multi-stage build. The idea is to avoid reusing a previously built image. To compute a helpful baseline, we need a sample project. I created one just for this purpose: it’s a relatively small Kotlin project. Here’s the relevant Dockerfile: Let’s execute the build: Here are the results of the five runs: The last command line used the DOCKER_BUILDKIT environment variable. It’s the way to tell Docker to use the legacy engine. If you didn’t update Docker for some time, it’s the engine that you’re using. Nowadays, BuildKit has superseded it and is the new default. BuildKit brings several performance improvements: Let’s re-execute the previous command on the new engine: Here’s an excerpt of the console log of the first run: The following executions of the same command have a slightly different output: Remember that we change the source code between runs. Files that we do not change, namely.mvn, mvnw and pom.xml, are cached by BuildKit. But these resources are small, so that caching doesn’t significantly improve the build time.

Continue reading...