Issue
I have a springbot application. What I'm trying to do is to create a docker image with all the libraries in it and then in my pipeline recall it to perform the compilation without downloading each time all the libraries. I'm using Azure devops and my Dockerfile for the image that should include all the libraries and perform the compilation is this:
FROM maven:3.8.4-openjdk-11-slim
WORKDIR /usr/src/app
COPY pom.xml /usr/src/app
RUN mvn dependency:go-offline -B
I copy the pom.xml with all the libraries and indeed when I run it I can see everything correctly downloaded.
Then in my pipeline I have this:
FROM myrepository.onazure.io/docker-compile-java:latest AS build-env <-- this is the image create above
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN mvn package -Dmaven.test.skip
# Build runtime image
FROM myrepository.onazure.io/docker-runtime-java:11
COPY --from=build-env /usr/src/app/target/*.jar /opt/app.jar
ENV PORT 9090
EXPOSE $PORT
CMD [ "sh", "-c", "java -jar /opt/app.jar --server.port=${PORT}" ]
The pipeline works fine but I can see during RUN mvn package -Dmaven.test.skip that the libraries have been downloaded again.
Solution
Try mvn package --offline ...
. The flag tells Maven to not resolve any dependency externally and only make use of the local repository.
See How can I get Maven to stop attempting to check for updates for artifacts from a certain group from maven-central-repo? for more info.
Answered By - Alex
Answer Checked By - Terry (JavaFixing Volunteer)