Bumped up to Java 10, but getting "Fatal error compiling: invalid target release: 10" in Docker/Spring-Boot/Maven setup

  docker, maven, spring-boot

Everything was working perfectly in my Docker setup. Then I had some code which used the new Java "var" feature. My Java version in my IDE was 8, so I bumped it up to 10 so that my code compiled with the new "var" feature. Everything is good with respect to my IDE.

I also have a maven-wrapper (with a mvnw command file) which gets packed into my docker container, and maven installed locally on my computer. Running both of these "maven"s work OK.

So in summary :

  • IDE build : OK
  • mvn build : OK
  • mvnw build : OK

But when I build my container I get this error :

#15 7.335 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project shape-shop-backend: Fatal error compiling: invalid target release: 10 -> [Help 1]

My docker file is two step.

  1. build application with mvnw.
  2. create the app.

All I did was changed the "FROM" lines from java 8 to java 10 :

FROM openjdk:8-jdk-alpine as build
FROM openjdk:8-jre-alpine

to

FROM openjdk:10-jdk-alpine as build
FROM openjdk:10-jre-alpine

My Docker file is :

#### Stage 1: Build the application
FROM openjdk:10-jdk-alpine as build

# Set the current working directory inside the image
WORKDIR /app
# Copy maven executable to the image
COPY mvnw .
COPY .mvn .mvn

# Copy the pom.xml file
COPY pom.xml .

# Build all the dependencies in preparation to go offline.
# This is a separate step so the dependencies will be cached unless
# the pom.xml file has changed.
RUN ./mvnw dependency:go-offline -B

# Copy the project source
COPY src src

# Package the application
RUN ./mvnw package -DskipTests
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)



#### Stage 2: A minimal docker image with command to run the app
FROM openjdk:10-jre-alpine

ARG DEPENDENCY=/app/target/dependency

# Copy project dependencies from the build stage
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app

ENTRYPOINT ["java","-cp","app:app/lib/*","com.shapeshop.App"]

Everything should be java 10, so I dont know why I am getting

Fatal error compiling: invalid target release: 10

Also my POM file is pointing to the correct version :

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>10</source>
            <target>10</target>
        </configuration>
    </plugin>

Source: Docker Questions

LEAVE A COMMENT