0

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.

NiBE
  • 857
  • 2
  • 16
  • 39
  • This does not answer your question, but offers you an alternative. In Azure Pipelines you can use the [cache task](https://learn.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#maven) for exactly this use case. To avoid downloading all maven dependencies in every pipeline run. – usuario Jan 27 '22 at 07:16
  • What's the use case for this because it looks like an unnecessary overhead? Are there other consumers of the `docker-compile-java:latest` image? I can't imagine because an app's set of dependencies are quite unique to the app itself. While we're at it obligatory mention of [SpringBoot layered jars](https://spring.io/blog/2020/08/14/creating-efficient-docker-images-with-spring-boot-2-3). – Alex Feb 18 '22 at 16:26

1 Answers1

0

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.

Alex
  • 1,313
  • 14
  • 28