Comments (5)
Now that .m2 is no longer a volume this should work
FROM maven:alpine
WORKDIR /usr/src/app
COPY pom.xml .
RUN mvn -B -e -C -T 1C org.apache.maven.plugins:maven-dependency-plugin:3.0.2:go-offline
COPY . .
RUN mvn -B -e -o -T 1C verify
FROM openjdk:alpine
COPY --from=0 /usr/src/app/target/*.jar ./
from docker-maven.
Facing similar issue. This proposal if/when done will help address the issue.
from docker-maven.
Sadly, I don't see how that RUN --mount
proposal will truly solve the problem. A Dockerfile may be built on a Windows machine, a Mac, or a Linux machine. The mount destination for MVN_REPO is a decision for the runner/builder, not the Dockerfile.
One idea that I can imagine is to declare a volume mount requirement. Imagine something like: REQUIRED_VOLUME MVN_REPO
is declared that essentially says, Volume MVN_REPO needs to be defined. Then, that logical volume may be used in the Docker build (or run). If the volume is not defined, it could error out. I could see this feature useful for all sorts of reasons, like declaring a destination for log files or database content.
from docker-maven.
Try using this
FROM maven
WORKDIR /usr/src/app
# /root/.m2 is a volume :(
ENV MAVEN_OPTS=-Dmaven.repo.local=../m2repo/
COPY pom.xml .
# v2.8 doesn't work :(
RUN mvn -B -e -C -T 1C org.apache.maven.plugins:maven-dependency-plugin:3.0.2:go-offline
COPY . .
RUN mvn -B -e -o -T 1C verify
FROM openjdk
COPY --from=0 /usr/src/app/target/*.jar ./
It caches the local repo like how the python onbuild Dockerfile does it. MAVEN_OPTS is needed because someone made /root/.m2/ a volume so stuff that goes in there doesn't get saved. verify is needed because "dependency:go-offline" doesn't work. You could probably just omit the "dependency:go-offline" part.
This sets it up so that changes to the pom.xml result in cache invalidation and redownload but other changes can just use the cache.
Edit: using a newer dependency:go-offline because the older one doesn't work.
from docker-maven.
@sixcorners I am trying to do exactly the same thing you are doing, but for some reason my maven offline install fails and says it can't find the POM.xml for some maven internal projects. Have you had a similar problem?
from docker-maven.
Related Issues (20)
- Removed ssh-client HOT 3
- Adding corretto-maven images based on Debian HOT 10
- Maven tag for JDK 20 HOT 3
- Errors running MavenCLI HOT 11
- 3.9.2 java 8 handshake_failure HOT 4
- Maven 3.9, unauthorized 401 when reaching MS AZURE repo with PAT HOT 6
- Please update bash in Alpine image to avoid error message HOT 1
- Latest images don't have ssh causing maven-release-plugin to fail HOT 10
- Could not create local repository at /home/user/.m2/repository
- Please add amazoncorretto + al2023 images HOT 2
- How to get 3.9.4 released? HOT 1
- Wrong docer example for eclipse-temurin-17 version? HOT 1
- amazoncorretto-11-debian ignores environment variables with a period HOT 1
- ETA on JDK 21 compatible image
- Corretto 21 + AL2023 HOT 5
- Add Eclipse Temurin 21 HOT 1
- /usr/local/bin/mvn-entrypoint.sh: 50: exec: 1: not found HOT 2
- maven: 3.6.3-openjdk-21 HOT 1
- Add Apache Maven 3.9.6
- Image maven:3.8.8 missing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docker-maven.