Java Toolchain issue in Docker "Unpacked JDK archive does not contain a Java home"

I’ve configured my project to use Java Toolchain and am trying to get it to compile in my GitLab CICD environment using the docker runner, however, I’m able to reproduce the issue on my development machine using Docker Desktop as well.

I’ve configured auto-provisioning using the foojay-toolchains plugin in my settings.gradle project as described in the documents and am trying to compile using the eclipse-temurin:11-jdk-alpine docker image.

The error I’m seeing is this:

FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':project:compileJava'.
> Could not resolve all dependencies for configuration ':project:compileClasspath'.
   > Failed to calculate the value of task ':project:compileJava' property 'javaCompiler'.
      > Cannot find a Java installation on your machine matching this tasks requirements: {languageVersion=8, vendor=Eclipse Temurin, implementation=vendor-specific} for LINUX on x86_64.
         > No matching toolchain could be found in the locally installed toolchains or the configured toolchain download repositories. Some toolchain resolvers had provisioning failures: foojay (Unable to download toolchain matching the requirements ({languageVersion=8, vendor=Eclipse Temurin, implementation=vendor-specific}) from 'https://api.foojay.io/disco/v3.0/ids/ac4c40cdd772fae20f1758b6fd9ac1d6/redirect', due to: Unpacked JDK archive does not contain a Java home: /root/.gradle/.tmp/jdks/OpenJDK8U-jdk_x64_linux_hotspot_8u442b0613882921797832945044.tmp).

I’ve filed a bug report with the foojay project, but it’s looking like it may be more of a gradle issue. I was not able to find any similar bugs or posts for this issue.

Does anyone know what I may be doing wrong or have seen a similar issue?

I am using gradle 8.12 and the toolchain I’m trying to use if Adoptium version 8

I created a sample project that can reproduce the issue I’m seeing GitHub - johnjaylward/gradle-toolchain-error

It is not a Gradle problem, but a problem of the foojay plugin.
On Alpine you have to use a JDK that is compiled for musl C library.
But the plugin does not detect it and downloads a JDK for glibc C library.
This cannot be executed and thus Gradle (correctly for the situation) says that there is no JDK in the archive, well, no useable JDK.

Your issue is a duplicate of Plugin fails to consider the type of the C library for Linux distributions · Issue #5 · gradle/foojay-toolchains · GitHub.

You can try to work-around it by installing compatibility packages or manually installing glibc or something like that, but the easiest would be you do not use an alpine-based image if you use toolchains, or you use an image where the required toolchains are already available so that none needs to be auto-provisioned.