Skip to content

Commit 18ed22e

Browse files
committed
docker: drop ineffective wrapper-jar exclusion from poms stage
The poms stage removed `.mvn/wrapper/maven-wrapper.jar` to try to keep the dependency-download layer stable across wrapper-jar changes. It didn't work: the build stage copies `.mvn/wrapper` (jar included) before the `COPY --from=poms` and the dependency `RUN` steps, so a wrapper-jar change still invalidates every later layer regardless of what poms emits. Making the dependency layers independent of the wrapper jar would mean giving up the offline prefetch or restructuring how Maven is invoked, and the wrapper jar changes rarely enough that it isn't worth that complexity. Revert the exclusion and correct the comments to describe the layer's actual cache inputs.
1 parent 0e45835 commit 18ed22e

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

Dockerfile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ WORKDIR /usr/src
66
COPY . .
77
# Wipe any files not called pom.xml or *.jar
88
RUN find . -type f -and \! -name pom.xml -and \! -name '*.jar' -delete
9-
# Drop the Maven wrapper jar from the `poms` stage output: the build stage copies `.mvn/wrapper` separately.
10-
# Keeping it here is redundant, and would make the `poms` stage output change when the wrapper jar changes.
11-
# (That output is later copied into the dependency-download layer.)
12-
RUN rm -f .mvn/wrapper/maven-wrapper.jar
139
# Clear up any (now) empty diretories
1410
RUN find . -type d -empty -delete
1511

@@ -23,8 +19,8 @@ RUN mkdir -p .mvn
2319
COPY .mvn/wrapper .mvn/wrapper
2420

2521
# 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 on the POMs (and the Maven wrapper scripts/config), it stays stable until one of those
27-
# inputs changes, so dependency downloads are reused whenever the source changes but the dependencies don't.
22+
# This layer depends on the POMs, the checked-in jars, and the Maven wrapper (copied above), so it stays cached
23+
# until one of those changes; dependency downloads are reused whenever the source changes but those inputs don't.
2824
COPY --from=poms /usr/src/ .
2925
# I don't know why we need all three either.
3026
RUN ./mvnw -e -B dependency:resolve-plugins -Dmaven.test.skip -Dmaven.repo.local=/tmp/m2_repo
@@ -36,7 +32,7 @@ RUN ./mvnw -e -B dependency:get -DgroupId=org.codehaus.plexus -DartifactId=plexu
3632
./mvnw -e -B dependency:get -DgroupId=org.junit -DartifactId=junit-bom -Dpackaging=pom -Dversion=5.13.4 -Dmaven.repo.local=/tmp/m2_repo && \
3733
./mvnw -e -B dependency:get -DgroupId=org.mockito -DartifactId=mockito-bom -Dpackaging=pom -Dversion=5.22.0 -Dmaven.repo.local=/tmp/m2_repo
3834

39-
# Above here is only affected by the pom.xml files, so the layer is stable.
35+
# Above here is affected only by the POMs, checked-in jars, and the Maven wrapper, so the layer is usually stable.
4036

4137
# Now, copy in all the source, and actually build it, skipping the tests.
4238
# The offline build reads the /tmp/m2_repo that the layers above populated.

0 commit comments

Comments
 (0)