Skip to content

Commit f892c67

Browse files
committed
docker: keep the dependency layer keyed purely on POM content
The poms stage now drops `.mvn/wrapper/maven-wrapper.jar` (the build stage copies `.mvn/wrapper` in separately), so a wrapper-jar change no longer invalidates the cached dependency layer. Other checked-in jars are still retained, as some are referenced by POMs and needed for the offline build.
1 parent 07c1ef9 commit f892c67

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

Dockerfile

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# This stage extracts all the pom.xml files.
2+
# It'll get rebuilt with any source change, but that's OK.
3+
# It doesn't matter what image we're using, really, so we may as well use one of the same images as elsewhere.
4+
FROM eclipse-temurin:17-jre AS poms
5+
WORKDIR /usr/src
6+
COPY . .
7+
# Wipe any files not called pom.xml or *.jar
8+
RUN find . -type f -and \! -name pom.xml -and \! -name '*.jar' -delete
9+
# Drop the Maven wrapper jar: the build stage copies .mvn/wrapper in
10+
# separately, and keeping it here would let a wrapper-jar change
11+
# invalidate the pom-only dependency layer.
12+
RUN rm -f .mvn/wrapper/maven-wrapper.jar
13+
# Clear up any (now) empty diretories
14+
RUN find . -type d -empty -delete
15+
116
# Now we build:
217
FROM eclipse-temurin:17 AS build
318
WORKDIR /tmp/
@@ -7,9 +22,9 @@ RUN chmod +x mvnw
722
RUN mkdir -p .mvn
823
COPY .mvn/wrapper .mvn/wrapper
924

10-
# First, copy in just the pom.xml files and fetch the dependencies into a real image layer. Because this
11-
# layer depends only on the pom.xml files, it stays stable until a POM changes, so dependency downloads
12-
# are reused whenever the source changes but the dependencies don't.
25+
# First, copy in the pom.xml files (and any checked-in jars) and fetch the dependencies into a real image layer.
26+
# Because this layer depends only on the pom.xml files, it stays stable until a POM changes, so dependency
27+
# downloads are reused whenever the source changes but the dependencies don't.
1328
COPY --from=poms /usr/src/ .
1429
# I don't know why we need all three either.
1530
RUN ./mvnw -e -B dependency:resolve-plugins -Dmaven.test.skip -Dmaven.repo.local=/tmp/m2_repo

0 commit comments

Comments
 (0)