JDK configuration in the Moderne CLI
By default, the Moderne CLI will try and detect what version of Java applies to a specific project and where the JDK is for said version. It will then pick the most optimal one when it goes to build each project.
In some situations, however, this may not be desirable. Perhaps you have a special location where the JDKs are saved, or perhaps the CLI detected the wrong version of Java for a project. In those instances, you can run certain mod config java
commands to tell the CLI what version of Java a project should use and where the JDKs are.
Let's walk through how to see what the defaults are and how you can add change them if desired.
JDK Defaults
By default, the Moderne CLI will look for JDKs in these locations (with the first one representing the one given the highest priority):
$PATH
$JAVA_HOME
Predictable OS installation paths
SDKMAN directories
Brew directories
Gradle toolchains
Environment variables
You can see the exact versions and their priority by running the following command:
Adding additional JDK locations
If you have JDKs installed in other places, you can add those by running the following command:
After running that, when a project is being built, it will prioritize looking for JDKs in the directory you specified over any other location.
Please note, though, that projects will only use this location if that appropriate version of Java exists there. This means, for instance, that if a project uses Java 17, but you specify a location that only has a Java 11 JDK, that the CLI will look elsewhere for the JDK. If it finds a Java 17 JDK anywhere else, it will use that one. If it can't find a JDK for the appropriate version of Java then it will error and the CLI commands won't work.
Specifying different Java versions
If you want to force the CLI to use a specific version of Java when building anything, you can run a command like:
17
can be more specific if you want a higher degree of control. For instance, it could be 17-tem
or 17.0.6-tem
.
If you want this version of Java to only apply to a specific group of repositories, you can add the --local <path>
parameter to the end of the command such as in:
If you want to revert to auto-detection for the Java version you can run one of the following commands:
If you want to see what Java version the CLI is currently using, you can run the following command:
Additional reading
For more information about each of the commands listed here, please see our CLI reference docs.
Last updated