FROM maven:3.6.3-jdk-14 as builder
WORKDIR application
COPY ./ ./
RUN mvn clean install

FROM openjdk:14 as layerBuilder
WORKDIR application
ARG JAR_FILE=application/target/*.jar
COPY --from=builder ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract

FROM openjdk:14
WORKDIR application
COPY --from=layerBuilder application/dependencies/ ./
COPY --from=layerBuilder application/spring-boot-loader/ ./
COPY --from=layerBuilder application/snapshot-dependencies/ ./
COPY --from=layerBuilder application/application/ ./

ENTRYPOINT ["java", "-Djava.security.cgd=file:/dev/./urandom", "-Dspring.profiles.active=DEV", "org.springframework.boot.loader.JarLauncher"]
