Is there a way to smoothly run side-by-side projects, each using different Java versions, in IntelliJ (v2022.x )?
For instance, I am using IntelliJ to work on two projects. One project is in Java 11 and the other is in Java 17 - each project has its own IDE instance. Each project is configured to use the proper JDK in the IntelliJ settings (Gradle and Project SDK). I also use skdman to switch the console to the correct version of Java depending on which project I am working on.
However, switching between projects causes the new project to load improperly - which is resolved by invalidating the caches and restarting rebuilding.
Is there a way to avoid invalidating the caches/restarting/rebuilding?
CodePudding user response:
You can specify the SDK for every project you have open in the settings
Project Settings -> Project -> Project SDK
I've also noticed some issues that were resolved by invalidation & restart, but only when you open the project for the first time and it hasn't got the SDK set properly. After you set it and restart it should remember the correct SDK to use for that project and load just fine.
Try to identify the scenario which has problems and consider opening a ticket if you're sure it's a problem: https://youtrack.jetbrains.com/issues/IDEA
There is a problem when working with tools ran from the command line, for example if you open terminal in IntelliJ it initializes things on startup, as if you opened up a shell on linux - even if you change environment variables the shell still has the same state from when it was opened - same goes for the terminal in IntelliJ.
This means that even if you change for example your JAVA_HOME for Maven to use different Java, it will still use the one that was set on startup.