Search code examples
javaspring-bootmavengoogle-app-enginedeployment

Getting java.lang.UnsupportedClassVersionError when deploying to Google App Engine


I developed a Spring Boot REST API and when I deploy it to Google App Engine using this guide, I'm getting the error [INFO] GCLOUD: java.lang.UnsupportedClassVersionError: org/springframework/boot/loader/JarLauncher has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 53.0.

I made sure to compile my application using Java 9 in maven via <java.version>9</java.version>. Then I also made sure to specify openjdk9 in my app.yaml for Google App Engine. I do a clean build and deployment using mvn clean install appengine:deploy -P cloud-gcp -DskipTests but the error persists.

According to this table, the code is apparently compiled using Java 17 (incorrect) but attempted to run using Java 9 (correct). As far as I know I didn't configure my code to be compiled with Java 17 anywhere.

EDIT:
Some Googling later, I found out that Spring Boot 3 requires a minimum of Java 17, that seems to be it. So I can't use Spring Boot 3 on Google App Engine since Google App Engine only supports openjdk8 and openjdk9 so I would have to downgrade Spring Boot as well which I don't want to do.

Is there any way to use e.g. openjdk17 on Google App Engine?


Solution

  • Based on this documentation on Java 11/17 runtime environment:

    The Java 11/17 runtimes use the latest stable release of the version that is specified in your app.yaml file. App Engine automatically updates to new patch release versions, but it will not automatically update the minor version.

    App Engine runs Java 11/17 apps in a container secured by gVisor on an up-to-date Ubuntu Linux distribution and its supported openjdk-11-jdk for Java 11 or openjdk-17-jdk for Java 17 runtime.

    • Java 11 runs on Ubuntu 18.04
    • Java 17 runs on Ubuntu 22.04

    You should declare in your runtime the runtime environment you wish to use:

    runtime: java17 # or another supported runtime
    entrypoint: java -Xmx64m -jar YOUR-ARTIFACT.jar