Every project uses a Software Development Kit (SDK). For Java projects, the SDK is referred to as the JDK (Java Development Kit). The SDK determines which API library is used to build the project. If a project is multi-module, the project SDK by default is common for all modules within the project. Optionally, individual SDKs for each module can be configured. For more information about SDKs, see SDK in the IntelliJ IDEA Web Help.
Getting Project SDK Information
The information about the project SDK is accessed via
ProjectRootManager like the following example shows
Getting and Setting Project SDK Attributes
To get the project-level SDK:Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk();
To get the project-level SDK name:String projectSdkName = ProjectRootManager.getInstance(project).getProjectSdkName();
To set the project-level SDK:ProjectRootManager.getInstance(project).setProjectSdk(sdk);
To set the project-level SDK name:ProjectRootManager.getInstance(project).setProjectSdkName(name);
See the project_model code sample to get more familiar with SDK manipulation toolset.
ProjectJdkTable can be used to query and modify configured SDKs.
Working with a Custom SDK
To create a custom SDK, provide a class extending
saveAdditionalData() blank, and register it in the
com.intellij.sdkType extension point.
To make SDK settings persistent, override
setupSdkPaths() and save settings by
To let a user select an SDK, see
However, it is not recommended to use "SDK" in non-IntelliJ IDEA IDEs. Although "SDK" is available in most JetBrains products,
ProjectJdksEditor is specific to Java, making the operation around "SDK" difficult. The recommended way of managing "SDK" settings is to create a
CustomStepProjectGenerator implementation and save settings in a
Assisting in Setting Up an SDK
Prompting the user with a notification to set up an SDK can help them get up-and-running with a plugin faster. The IntelliJ Platform offers the extension point
com.intellij.projectSdkSetupValidator, where you can register an implementation of
ProjectSdkSetupValidator to notify the user if they are missing an SDK.
The following is a simplified example that checks whether an instance of "DemoSdk" has been configured in the project when the user opens a "DemoFileType":
isApplicableFor()checks what condition(s) should be met to run the validation.
getErrorMessage()runs the validation and return an appropriate error message if the validation fails.
If the validation is successful, then it should return null.
EditorNotificationPanel.ActionHandlerthat enables the user to execute a quick-fix to resolve the validation issue.