I'm having trouble getting either of the two Cloud Native Buildpacks builders I've tried (gcr.io/buildpacks/builder:v1
and paketobuildpacks/builder:base
) to fully detect my desired Java version so that the right JVM is used to build my project and to run it. It seems to successfully detect my desired version as it completes the build step, but I notice in the logs during the build that it ends up downloading a version 11 JDK and I get an error when trying to run a container from the built image:
Error: LinkageError occurred while loading main class com.mattwelke.javatests.JavalinPostgresJdbc
java.lang.UnsupportedClassVersionError: com/mattwelke/javatests/JavalinPostgresJdbc 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 55.0
This error infers that it chose to use JDK 17 to build the class files but then JDK 11 to run them.
My project structure is the one produced by running gradle init
and choosing "application" as the type of project to be created, except I moved the contents of app
up into the root and deleted settings.gradle
. I found that I had to do that in order for the first builder I tried to be able to detect it as a Gradle project in the first place. I also had to add id 'com.github.johnrengelman.shadow' version '7.1.2'
to the plugins
section of build.gradle
, otherwise the builder failed to build, with an error about not being able to find a main class.
I added the following to build.gradle
to indicate my preferred Java version for the project:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
I thought that this might be something I'm doing wrong, therefore being a good reason to post to Stack Overflow, instead of raising a GitHub issue in either of the repos for the two builders I tried, because I got the exact same error with both builders (the one from Google and the one from Paketo).