- Pin to eclipse-temurin:21.0.10_7-{jdk,jre}-noble for reproducible builds
- Switch -DskipTests to -Dmaven.test.skip=true: skips test compilation entirely,
not just execution — faster and avoids build failures from test-only missing classes
- Add comment on COPY *.jar explaining why the glob is safe (Spring Boot renames
the pre-repackage artifact to .jar.original, leaving only one .jar in target/)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
19 lines
670 B
Docker
19 lines
670 B
Docker
FROM eclipse-temurin:21.0.10_7-jdk-noble AS builder
|
|
WORKDIR /app
|
|
|
|
# Copy wrapper and POM first — dependency layer is cached separately from source
|
|
COPY .mvn .mvn
|
|
COPY mvnw pom.xml ./
|
|
RUN --mount=type=cache,target=/root/.m2 ./mvnw dependency:go-offline -q
|
|
|
|
COPY src ./src
|
|
# -Dmaven.test.skip=true skips test compilation entirely (not just execution)
|
|
RUN --mount=type=cache,target=/root/.m2 ./mvnw clean package -Dmaven.test.skip=true -q
|
|
|
|
FROM eclipse-temurin:21.0.10_7-jre-noble
|
|
WORKDIR /app
|
|
# Spring Boot repackages to *.jar; pre-repackage artifact uses .jar.original, not .jar
|
|
COPY --from=builder /app/target/*.jar app.jar
|
|
EXPOSE 8080
|
|
CMD ["java", "-jar", "app.jar"]
|