Custom SDK and JDK in the same project


Hi, I'm developing a custom language plugin for which I have created a custom SDK. I would like that my project is able to support besides my custom files also Java files.

My module builder extends from `com.intellij.ide.util.projectWizard.JavaModuleBuilder`, but when I open a .java file in my custom project, the project cannot resolve the java dependencies because the JDK is not configured as the project SDK.

Is it possible to configure the JDK as a project dependency or as a library? or do I need to include it somehow in my custom SDK? I have looked at the method `com.intellij.openapi.projectRoots.SdkTypeId.saveAdditionalData` but I'm not sure if this is the correct path.

Thanks in advanced, Carmen


SDK and Libraries are two distinct concepts. Could you please explain how your custom SDK replaces/augments the Java SDK? Did you consider using Facets for your custom setup instead eventually? (


The Java class library can be accessed from within the custom language, e.g., is possible to instantiate Java classes. Then my custom project needs to have JDK as external library as well. Otherwise java classes are not found.

At the moment I solved the problem adding java classes in my custom SDK with the following code. The developer selects the JDK when creating the project. This way when the project is created in the custom SDK I can have my custom files together with the java classes from the JDK.

I have not consider the facets in the setup yet. Do you think I should consider them over my current solution? Thank you.

for (VirtualFile file : javaSdk.getRootProvider().getFiles(OrderRootType.CLASSES)) {
sdkModificator.addRoot(file, OrderRootType.CLASSES);

If this solution works well for you, then it's fine. But SDK ofcourse offers more, e.g. link to sources/javadocs etc. you could possibly add.

Facets are more of a specialization/framework configuration for a Module.


Hi, I would like to make the JDK version for my custom SDK configurable, this means that the user can be able to change the JDK version. 

Following the implementation of org.jetbrains.idea.devkit.projectRoots.Sandbox of DevKit plugin, I have implemented the interface 'com.intellij.openapi.projectRoots.ValidatableSdkAdditionalData' and I have extended from 'com.intellij.openapi.projectRoots.AdditionalDataConfigurable'. However, when in my custom combobox in the SDK editor I changed the JDK for my custom plugin I cannot set the new selected version for the project.

Could you please tell me what I'm missing? This is the method I invoke when the new jdk is selected. I removed all roots and add the new ones, but although the modificator commit the changes the additional data for the SDK in my project is not updated the new files.

Thank you, Carmen

private void addJdk() {
jdkSelected = (Sdk) combo.getItem();
if (!isJDKEmpty()) {
MySdkAdditionalData data = new MySdkAdditionalData(jdkSelected);
SdkModificator modificator = newSdk.getSdkModificator();
MySdkAdditionalData oldData = ((MySdkAdditionalData)newSdk.getSdkAdditionalData());
if (oldData != null) {
Sdk oldJdk = ((MySdkAdditionalData)newSdk.getSdkAdditionalData()).getCurrentJavaSdk();
if (oldJdk != null && !jdkSelected.getVersionString().equals(modificator.getVersionString())) {
removeRootsFromOldJdk(modificator, oldJdk);

//new jdk data
configureJavaJars(modificator, jdkSelected); //this method adds java files to the sdkModificator as I showed in the code posted in 09/09/2021

Also, in the constructor of my MySdkDataConfigurable class (which implements AdditionalDataConfigurable), I have the field mySdkModificator, but invoking mySdkModificator.setSdkAdditionalData(SdkAdditionalData data) returns UnsupportedOperationException (from the com.intellij.openapi.projectRoots.ui.SDKEditor class), then I used the modificator of the sdk I get from 'setSdk' method. Could you tell me if do I need to override the SDKEditor.setSdkAdditionalData method?

public MySdkDataConfigurable(@NotNull SdkModel sdkModel, @NotNull SdkModificator sdkModificator) {
mySdkModel = sdkModel;
mySdkModificator = sdkModificator;

Please sign in to leave a comment.