# syntax=docker/dockerfile:1
FROM gradle:jdk8-ubi9 AS builder
WORKDIR /workspace
# Copy Gradle wrapper and build files
COPY gradlew .
COPY gradle ./gradle
COPY build.gradle ./build.gradle
COPY src ./src
RUN chmod +x gradlew
# Build the project (this will download dependencies and compile sources)
RUN ./gradlew clean build -x test
# Runtime stage reuse the same base image for compatibility
FROM gradle:jdk8-ubi9
WORKDIR /app
# Copy built artifacts from the builder stage
COPY --from=builder /workspace/build/libs /app/libs
# Ensure the libs directory exists
RUN mkdir -p /app/libs
# Run the library JAR if present
ENTRYPOINT ["bash","-lc","JAR=$(ls /app/libs/*.jar 2>/dev/null | head -n 1 || true); if [ -n \"$JAR\" ]; then exec java -jar \"$JAR\"; else echo 'No jar found in /app/libs'; fi"]