0

I use dependency:go-offline to avoid redownloading in my Docker build. Yet the docker build -t myimage . causes the jars to be redownloaded. How can I prevent redownloading?

Relevant part of the Dockerfile.

FROM maven:3.8.3-jdk-8 AS build
COPY src /usr/src/app/src  
COPY pom.xml /usr/src/app
COPY run.sh /usr/src/app
RUN mvn -f /usr/src/app/pom.xml dependency:go-offline
RUN mvn -f /usr/src/app/pom.xml install dependency:copy-dependencies

FROM gcr.io/distroless/java
COPY --from=build /usr/src/app/ .

ENTRYPOINT ["./run.sh"]
Joshua Fox
  • 18,704
  • 23
  • 87
  • 147

1 Answers1

0

Use the -o switch. This enables offline build.

See https://stackoverflow.com/a/7233762/927493

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Thank you. That might help or `mvn install` However, the redownload occurs in `go-offline` – Joshua Fox Oct 27 '21 at 16:11
  • Also, for `mvn install`, the `-o` switch results in this error `Unable to parse configuration of mojo org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce for parameter requireUpperBoundDeps: Cannot create instance of class org.apache.maven.plugins.enforcer.RequireUpperBoundDeps: org/apache/maven/shared/dependency/tree/DependencyTreeBuilderException: org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException -> [Help 1] ` – Joshua Fox Oct 27 '21 at 16:14