Working with SDKs
- What are SDKs for?
- Supported SDKs
- SDK levels
- SDK contents (classpath, sourcepath, and documentation paths)
- Defining an SDK when creating a project or module
- Managing global, project and module SDKs
- Making Apple JDK sources accessible in IntelliJ IDEA on macOS
What are SDKs for?
IntelliJ IDEA does not include an SDK. So, before you start writing your code, you have to download and install at least one SDK, and define it in IntelliJ IDEA. (You can specify an SDK when creating your first project or at a later time.)
To define an SDK in IntelliJ IDEA, generally, all you have to do is to specify its location. (This location, normally, is referred to as the SDK home directory. This is the directory in which the SDK is installed). Additional SDK adjustments are possible, however, in most of the cases, they are not necessary.
Depending on the nature of your application, you can use:
- Java SE Developments Kits (JDKs) to develop Java desktop and enterprise applications.
- Mobile SDKs (Java Micro Edition (ME) SDKs) to develop applications for Java-enabled mobile devices.
- Android SDKs to develop applications for Android devices.
- Flex and AIR SDKs to develop applications for the Adobe Flash platform.
- Flexmojos SDKs to launch the Flex compiler and debugger. (Such SDKs are created by IntelliJ IDEA automatically when importing Flexmojos projects.)
- IntelliJ Platform Plugin SDKs to develop plugins for IntelliJ IDEA. (An IntelliJ IDEA installation acts as an IntelliJ Platform Plugin SDK.)
Note that the set of supported SDK types depends on the IntelliJ IDEA edition being used (Community or Ultimate) and also on which plugins are currently enabled.
All the SDKs, generally, are global: irrespective of when and where you define an SDK, you can then use it in any of your projects.
One of the SDKs is assigned to a project and is referred to as a project SDK. This SDK is used by default by all the modules of the corresponding project.
A module can use ("inherit") the project SDK, or, alternatively, a module-specific SDK can be specified.
SDK contents (classpath, sourcepath, and documentation paths)
When you define a new SDK, IntelliJ IDEA analyses the contents of the SDK installation folder (home directory) to find out where the corresponding binaries, sources and associated documentation are located. As a result, all the appropriate locations within the SDK are translated into corresponding paths and assigned to one of the following categories:
Classpath. This is a set of paths to directories and archives containing the SDK binaries. For a JDK, for example, this set includes the paths to class directories and JAR files that make up the Java API and its extensions.
You can add more SDK libraries to this set, however, this is never necessary for any standard SDK.
Sourcepath. This is a set of paths to directories and archives containing the source code for the SDK binaries included in the classpath set.
Including the source files isn’t required, but doing so improves IntelliJ IDEA’s ability to provide inline help while coding (or Ctrl+Q).
Documentation paths. This is a set of paths to documentation that describes the SDK source code.
Including documentation paths is also optional, but doing so gives you the ability to view documentation directly from the IDE (or Shift+F1).
If online documentation is available for the SDK, you can add the corresponding URL to the SDK documentation paths () to be able to access this documentation when needed.
Defining an SDK when creating a project or module
You can define a new SDK when creating a project or module. See e.g. Creating a project in Creating, Running and Packaging Your First Java Application.
As a result, the SDK definition will appear at the IDE level. In addition to that:
- If you defined an SDK when creating a project, the SDK will be assigned to the project as the default project SDK. The module that is created together with the project will inherit the project SDK.
- If you defined an SDK when creating a module, the SDK will be assigned to the module.
Managing global, project and module SDKs
Most of the tasks related to working with SDKs are performed in the Project Structure dialog ( ). Depending on the SDK level:
Global (IDE). To see all the SDKs that you have available, select SDKs.
To define a new SDK, click , select the SDK type (e.g. JDK), and then specify the SDK installation directory.
Project. To see which SDK is being used as the project default SDK, select Project.
If you want to use a different SDK, select that SDK from the list. If the SDK that you want is not defined in IntelliJ IDEA yet, click New to start adding its definition.
Note that if you change the project SDK, all the modules that are using the default project SDK will change their SDK accordingly.
Module. To see which SDK is used by a module, select Modules, select the module of interest, and then select Dependencies.
If you have the text Project SDK in the Module SDK field, the module is using the project default SDK. To specify a different SDK for the module, use the list or the New button.
Making Apple JDK sources accessible in IntelliJ IDEA on macOS
The Apple JDK included in macOS installation doesn't contain the JDK sources. So to make those sources accessible in IntelliJ IDEA, you should download and install the Java for macOS Developer Package and then add the JDK sources contained in this package (
src.jar) to the definition of the corresponding JSDK in IntelliJ IDEA.
- In a Web browser, go to the Downloads for Apple Developers page.
- Sign in to the downloads page using your Apple developer account (Apple ID and password).
- Download and install the Java for macOS Update Developer Package suitable for the macOS version that you are using.
- In IntelliJ IDEA, open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S) and select SDKs.
- Select the Apple JDK of interest. (If the corresponding JDK is not present in the list, add its definition: , etc.)
- On the SDK page shown in the right-hand part of the dialog, select the Sourcepath tab and click (Alt+Insert).
- In the dialog that opens, select the file
src.jarand click OK.
(Usually, this file is located in
<java.version>is your JDK version, for example,
1.6.0_31-b04-415.jdkor something similar.)
- Click OK in the Project Structure dialog.