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"]
