Java the weed
A longer story ...
Java is like a weed: a plant whose growth cannot be controlled. As in real life, you have to check from time to time where it has installed itself and you have to remove it manually, because - at least in my Windows machine - not one JAVA SDK is listed under Apps.
The problem with that is that you never know which Java SDK (or run-time) is used when you use Java. The first one installed, the last one installed, the one with the highest version number ... what if there are two distributions with the same version, which one is updated automatically and so on.
To avoid unpredictable and unexpected results when using IntelliJ with Groovy you must control your Java installations!
Observations
One day, I recognized a growing list of SDKs in my IntelliJ project:

The first action I took was to search for "java.exe" which gave me some insight where to look for weed.

Alternatively, on Windows you can run where /R groovy.bat and where /R java.exe to find all SDK locations on your machine.
Actually, I wanted
one Java SDK and distribution (I use Amazon Corretto v23)
the ATOM SDK:
C:\Program Files\Boomi AtomSphere\LocalAtom\jre\binSome applications, especially JetBrains Apps like IntelliJ, install their own, local run-time,, which you will want to keep!
Confusion
There is no other way to check for Java installations on your machine then searching for "java.exe" - omg!
You may use where java on the command-line or you want to check the JAVA_HOME environment variable:
and you will be confused even more!

Get rid of it
Close IntelliJ and all other applications that might lock Java.
Pick all the paths containing a java.exe which you don't want.
Delete these directories using a console window with ADMIN rights.
Gradle
Gradle is a Java build tool. You may have it or not but you may notice it is even worse than Java:

I delete my .gradle cache folder from time to time (incl. the included Java distributions) to get a fresh Gradle setup: rmdir /s /q "V:\packages\.gradle". The next time I use Gradle it downloads and installs back automatically but I got rid of all the old and unused versions that were littering my computer.
For example, the ScriptEaseLib is built with Gradle. Every time I build it, the Gradle toolchain is downloaded if it does not exist. It takes a minute or two ...

Clean! Start over! Clean install!
Close all JAVA apps
Close IntelliJ
Close all JetBrains apps, incl. ToolBox
Check Task Manager that Java isn't running anymore
Alternatively: log-off and log-on again
Find your preferred distribution, for example: Amazon Corretto 23.
Ensure you are running a complete installation incl. environment variables etc.

Unfortunately there are two (Windows) environment variables: for the current user and for system. The user setting has preference and the Corretto installation sets the system variable. Delete the user's JAVA_HOME and go with the just installed system setting:

Fix IntelliJ
IntelliJ will now list orphaned references:

Leave the ATOM JDK and remove all other entiries.
Add the one and only that you have just installed

Fix your Project Settings

* Make sure all your modules (normally there is only one) use the Project SDK

Final Checks
Open a new console window! If you had an open console, this has not recognized all the changes you made!
Last updated