Help: newly created daemon process has a different context than expected


Could anyone help me for this problem:
We need to run some gradle build in a docker image based on eclipse-temurin:17-alpine, I have installed java 8 and java 11 then so that I can build some gradle project with different JDK which is different from the default one 17.

Then i use this command line in my program: ./gradlew build “PATH to jdk 8”, but i got some error:

The newly created daemon process has a different context than expected.
It won't be possible to reconnect to this daemon. Context mismatch: 
Java home is different.
Wanted: DefaultDaemonContext[uid=null,javaHome=/usr/lib/jvm/java-8-openjdk,daemonRegistryDir=/home/gradle/daemon,pid=3982,idleTimeout=null,priority=NORMAL,daemonOpts=--add-opens,java.base/java.util=ALL-UNNAMED,--add-opens,java.base/java.lang=ALL-UNNAMED,--add-opens,java.base/java.lang.invoke=ALL-UNNAMED,--add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,-Xmx1536m,-Dfile.encoding=UTF-8,,-Duser.language=en,-Duser.variant]
Actual: DefaultDaemonContext[uid=ac5ffb31-7572-4cda-884d-87da31d4a163,javaHome=/opt/java/openjdk,daemonRegistryDir=/home/gradle/daemon,pid=4048,idleTimeout=10800000,priority=NORMAL,daemonOpts=--add-opens,java.base/java.util=ALL-UNNAMED,--add-opens,java.base/java.lang=ALL-UNNAMED,--add-opens,java.base/java.lang.invoke=ALL-UNNAMED,--add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,-Xmx1536m,-Dfile.encoding=UTF-8,,-Duser.language=en,-Duser.variant]

But when i changed the default JDK to 11, i can build the same command with jdk 8…

And if i run like this:
bash -c JAVA_HOME=/usr/lib/jvm/java-8-openjdk & ./gradlew build --info ,

i got this error:

* What went wrong:
Could not open cp_init remapped class cache for bczvo6q9udzcgcqk82m9zxs5o

I have searched so many but i found nothing imcompabilities about jdk17 and gradle …

I am really confused now

Thank you for your help,

For anyone who have the same issue like me,

There is a known issue for alpine and gradle when build with different jdk inside one docker image: Toolchain feature detects Java 8 JDK as a different Java version when inside an Alpine Linux container. · Issue #24300 · gradle/gradle · GitHub

To resolve such problem, For now, gradle propose to change alpine to ubuntu: Add a note to documentation about toolchains limitations with musl library by ov7a · Pull Request #24511 · gradle/gradle · GitHub