Perhaps you can specify a JAVA_HOME variable in the run configuration for the JDK you want? You may also be able to change your gradle JVM version if that’s an option like below.
Gradle JDK has to be Java 16, since one half of the project is a Java 16 project.
The other half is legacy and has to use Java 8
I even set the Gradle JDK to Java 8 for one half of my project and to Java 16 for the other half.
Still intellij seems to use what is configured as Project SDK for running unit tests.
Of course it uses the project SDK if you don’t delegate the test execution to Gradle.
The Gradle JVM is only used - well - to execute Gradle.
That’s why “Build/Run with Gradle” and “Test with Gradle” are the defaults, because Gradle usually knows better how to do the things a project needs.
If IJ does not get the JDK right, you should open an issue with JetBrains YouTrack probably.