I'm trying to improve the building time of a project Image (Quarkus + Maven + JDK17), by using Docker's caching feature. I found some stuff online but only got me this far on the solution, here's the Dockerfile I'm using:
#1st STAGE
FROM maven:3.8.5-openjdk-17 AS build
WORKDIR /app
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src ./src
RUN mvn -f pom.xml package
#2nd STAGE
FROM azul/zulu-openjdk-alpine:17-jre
WORKDIR /app
CMD "java" "-jar" "/app/application.jar"
So basically I'm copying only the pom.xml
from the project, trying to download all the dependencies before building the project and only after this I'll build the project, but the problem I'm facing is:
Whenever I change anything on my source code that is located under src
, it still downloads some dependencies, in which I suppose should have been downloaded on the RUN mvn dependency:go-offline
step. There are other steps here that are necessary and I'm missing?
Notes:
1 - I have the go-offline
plugin added to the pom.xml
with 3.1.2
version.
2 - It seem to only download dependencies from the framework I'm using (Quarkus).
I've already tried adding:
RUN mvn dependency:resolve
RUN mvn dependency:resolve-plugins
Also tried the build-kit
from docker.
There's also this one: Unable to cache maven dependency in docker image
All together, and all separated but no success.
A simple reproducible example would be to create a new Quarkus project, use this Dockerfile and add a simple hello world
, build, and then after changing it, no dependencies should be downloaded, since no new dependencies were added since the last build.
PS.: One thing that I've noticed, is that if I try to run
mvn package -o
on my machine I'll get the following error:
Plugin org.apache.maven.plugins:maven-dependency-plugin:3.1.2 or one of its dependencies could not be resolved: Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact org.apache.maven.plugins:maven-dependency-plugin:jar:3.1.2 has not been downloaded from it before.
But as you can imagine, I've already run the 'package' command several times, so I guess the dependencies should be under '.m2' repository, why the error?