How to define IDEA JDKs from environment variables? - intellij-idea

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?

IDE resolves the JVM for Gradle using below algorithm:
Checks the gradle.properties file for the appropriate Gradle JVM specified in org.gradle.java.home and uses it for the project.
Then it checks the JAVA_HOME environment variable.
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

Related

Pros and Cons with installing Kotlin standalone compiler instead of using IntelliJ Kotlin plugin?

i understand that i can use Kotlin Plugin comes with IntelliJ but i can also install Kotlin standalone compiler. Is there any pros/cons using standalone vs IntelliJ own integrated?
I'd say that:
Any real Kotlin project (including projects in IntelliJ) should use a build system such as Gradle or Maven.
Enabling Kotlin support in a Gradle/Maven project will automatically download the correct compiler (and switch it when you update the Kotlin version in the config file) and not care about whether you have a stand-alone version installed.
Any other Kotlin tool will likely be integrated with them as well.
So the standalone compiler is pretty much only useful when you want to try something quickly outside any project, but then https://play.kotlinlang.org/ or https://try.kotlinlang.org/ can work as well; and again let you switch between Kotlin versions simpler than a manually installed compiler.
Running Kotlin scripts may be the only case where I would use the stand-alone compiler.
Not much, but having own install have few advantages, but probably not needed by most people on their machines:
You don't need intellij, so you can use that compiler in other IDE or just for other applications
You can use different version of compiler than the one from plugin.
But in most cases integrated one is all you need.

How do I change the JVM used to run IntelliJ on Windows

I have two Java JDKs installed on my workstation, with jdk1.6.0_41 in my path, and jdk1.7.0_21 available as well, but not in the path.
How can I configure IntelliJ IDEA 13 to use a particular JVM? To be clear, I want to set the JVM used to run IntelliJ itself, not the SDK used for running my code. I am running Windows 7 Enterprise Edition and launch IntelliJ 13.0.2 by running idea64.exe
I have set JAVA_HOME to point to jdk1.7.0_21 but according to the About box it is using jdk1.6.0_41.
This FAQ on the JetBrains web site describes how to do this for Mac, but not for Windows.
This answer suggests using the IDEA_JVM environment variable for Ubuntu 12, but I have tried that and it isn't working.
I suspect you have another setting that is overriding your JAVA_HOME
From Jetbrains docs:
idea64.exe uses this JDK search sequence:
IDEA_JDK_64 environment variable
..\jre64 directory
system Registry
JDK_HOME environment variable
JAVA_HOME environment variable
With newer versions the environment variables are ignored. Instead there is a new action "Choose Boot Java Runtime". The easiest way to get to it is via "Find Action" Ctrl+Shift+A.
You can also edit the setting via the .jdk file in your user configuration directory, e.g. %APPDATA%\JetBrains\IntelliJIdea2021.3\idea64.exe.jdk. This is a plain text file containing only the path to the JDK.
It is not recommended to do this, and you should use the JDK that is bundled with IDEA.
CTRL+ALT+SHIFT+S to go to Project Structure
Under Platform Settings, go to SDKs.
Use the + green icon to add a new SDK and set it to that one.

OSGI aware IDE at development time

I'm starting development using OSGi but when one of my concerns is about the lack of support at development time, meaning that commonly IDEs (started using Intellij IDEA) don't use OSGi for class discovery but classpath search IDE managed (I'm in search for one that uses OSGi instead).
The main concern here is to prevent classpath issues at execution time by suing the same OSGi mechanisms at development time.
Does any IDE work this way ?
update: added link to blog post with my experience with IDEA
OSGi is a runtime technology, therefore there is no such thing as an OSGi mechanism at build time. Also bear in mind that ultimately all Java code must be compiled by a Java compiler, usually javac. The javac compiler does not use package dependencies like Import-Package, it always uses JARs or directories on the classpath.
Having said that, Bndtools uses package filtering at build time, based on the exported and private packages of the dependencies. This is a special feature of Eclipse and it does not work when you compile outside of the IDE, e.g. with Ant or Maven. However it may still be useful because if you try to use a non-exported package from another bundle you will get a problem marker with a red X in the Eclipse IDE.

Using KDevelop during development of a shared library

I'm trying to use KDevelop as an IDE for development of a C++ shared library. An earlier posts here indicate that I need to edit a CMake makefile for doing that. This is quite painful and very time consuming as it means converting our custom gmake-oriented build system into something of CMake.
Is there any other way for doing that?
KDevelop doesn't force you to use a specific buildsystem like many other IDEs do. CMake is just the default as it's very well integrated and many if not all KDE projects use cmake.
You can use a different build system by choosing "Custom Buildsystem" or "Custom Makefile Project Manager".
Custom Makefile Project Manager simply calls "make" - your current build system should work this that.

How to setup project based environment variable for IntelliJ IDEA?

I do have a MAVEN based java project that requires some environment variables.
So far, I used a setenv bash script to setup them and added few other scripts in the project root to call it and do build, test...
The question is how can make this work with IntelliJ IDEA?
Not supported yet, please vote for this feature.