Pedro Lamarão
Pedro Lamarão

Reputation: 531

How to define IDEA JDKs from environment variables?

We have a preexisting developer kit which contains a variety of different JDKs we need because of reasons. This kit defines environment variables such as JDK_7 and JDK_8 pointing to the appropriate directories. These paths are stable inside the kit but are not stable between developer's and build automation machines. The build scripts we use for build automation rely on these variables to set the appropriate JDK in each case. Gradle recently introduced support for detecting toolchains from environment variables, which we are using with great success.

We are now evaluating using IntelliJ IDEA as an IDE for our projects, motivated by its great Gradle support. How can we configure IDEA with JDKs from environment variables?

It is acceptable for us to create a custom plugin to adapt IDEA to our developer kits. What extensions points can we use to inject JDKs into IDEA's platform or project settings?

Upvotes: 1

Views: 287

Answers (1)

Andrey
Andrey

Reputation: 16391

IDE resolves the JVM for Gradle using below algorithm:

  1. Checks the gradle.properties file for the appropriate Gradle JVM specified in org.gradle.java.home and uses it for the project.

  2. Then it checks the JAVA_HOME environment variable.

  3. Then it checks the closest appropriate JDK version for the existing Gradle version.

There are related requests:

  • IDEA-240044 Path Variable for the default project JDK
  • IDEA-151340 Allow path variables to reference environment variables

Upvotes: 1

Related Questions