How to change java version in intellij idea

How to change java version in intellij idea

Change the boot Java runtime of the IDE

As a Java application, IntelliJ IDEA requires a Java runtime environment (JRE). By default, IntelliJ IDEA uses JetBrains Runtime (a fork of OpenJDK), which is included with the IDE. JetBrains Runtime fixes various known OpenJDK and Oracle JDK bugs, and provides better performance and stability. However, in some cases you may be required to use another Java runtime or a specific version of JetBrains Runtime.

Changing the boot Java runtime may cause unexpected problems. Do not change it unless you were specifically asked to do so by JetBrains support.

The runtime for IntelliJ IDEA is not the same runtime used for your applications. Define an SDK for each of your projects, which includes the necessary development and runtime environment.

When using a non-default Java runtime for IntelliJ IDEA, it will not update with the IDE and may not be compatible with the new version. Reset back to the default runtime when updating IntelliJ IDEA to get the latest compatible version of JetBrains Runtime.

Switch the Java runtime used to run IntelliJ IDEA

Find and select the Choose Boot Java Runtime for the IDE action.

If necessary, you can change the location where IntelliJ IDEA will download the selected runtime.

Wait for IntelliJ IDEA to restart with the new runtime.

When you open the Choose Boot Runtime for the IDE dialog for the first time, it may take a while to load the list of JetBrains Runtime builds from the server.

The path to the selected runtime is stored in the idea.jdk or idea64.jdk file in the IntelliJ IDEA configuration directory. If there are problems with the selected runtime, you can delete this file to revert to the default runtime.

You can also override the runtime used for IntelliJ IDEA by adding the IDEA_JDK environment variable with the path to the desired JDK home directory.

How do I change the Java version I’m using in IntelliJ (and Maven)?

I’m working on a simple Java project and trying to use IntelliJ 14 for the first time; I have the Ultimate version through an education license (in my last year of undergrad!). I’m not super familiar with either Maven or IntelliJ. I want to use Java 8, and in fact I’m pretty sure this is the only version of the JDK I have installed on my computer. However, whenever I compile my project, I get a couple warnings and an info message:
Information: Using javac 1.8.0_51 to compile java sources
Warning: java: source value 1.5 is obsolete and will be removed in a future release
Warning: java: target value 1.5 is obsolete and will be removed in a future release

included the following in my maven pom

Changed the IntelliJ preference file as noted here on the IntelliJ website.

Set the global, project, and module SDK as noted here on the IntelliJ website.

Am I missing a setting somewhere? What do I have to do to keep this value from changing every time I re-open IntelliJ?

2 Answers 2

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

Try using the maven compiler plugin in your pom.xml and set the source/target level accordingly. IDEA will change the project settings according to this setting

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

I’m using IntelliJ IDEA 2017.2. To build the project (using Ctrl+F9), changing the maven-compiler-plugin source and target versions was not enough. I had to:

Then I ran into this other problem. To solve it, I had to:

Aside: I’ve been using IDEs since Turbo Pascal 2.0 in the 80s. I find it counter-intuitive that such a modern IDE makes it so hard to open the «Project Settings». First, if you right-click the project (top left on the main window) there’s no option to open project settings. Second, the «Project» bar on the top left of the main window has the gear symbol with a drop-down list, but no option to access project settings there either. Third, if you right-click the project directory in the project explorer view on the left, you see «Open Module Settings» but there’s no «Project Settings». Fourth, if you open File on the main menu, you’ll see «Settings», «Other Settings» but no «Project Settings». Counter-intuitive. :^|

How to change java version in intellij idea

Generally, SDKs are global. It means that one SDK can be used in multiple projects and modules. After you create a new project and define an SDK for it, you can configure modules in this project to inherit its SDK. You can also specify an SDK for each module individually. For more information, refer to Change module SDK.

Supported SDKs

Define an SDK

Configure global SDKs

To add an SDK, click How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea, select the necessary SDK and specify its home directory in the dialog that opens.

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

Set up a project SDK

If the necessary SDK is already defined in IntelliJ IDEA, select it from the SDK list.

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

Set up a module SDK

If the necessary SDK is already defined in IntelliJ IDEA, select it from the Module SDK list.

If you want a module to inherit a project SDK, select the Project SDK option from the Module SDK list.

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

Java Development Kit (JDK)

To develop applications in IntelliJ IDEA, you need a Java SDK (JDK). A JDK is a software package that contains libraries, tools for developing and testing Java applications (development tools), and tools for running applications on the Java platform (Java Runtime Environment — JRE).

The JRE can be obtained separately from the JDK, but it’s not suitable for application development, as it doesn’t have essential components such as compilers and debuggers.

The bundled JRE is used for running the IDE itself, and it’s not sufficient for developing Java applications. Before you start developing in Java, download and install a standalone JDK build.

Due to the changes in the Oracle Java License, you might not have the rights to use Oracle’s Java SE for free. We recommend that you use one of the OpenJDK builds to avoid potential compliance failures.

In IntelliJ IDEA, you can download a JDK package right from the IDE, or you can manually download the necessary JDK distribution and define it in the IDE.

For a manual download, use any available distribution that you like, for example:

If you don’t know which distribution to choose, and you don’t have specific requirements that instruct you to use one of the existing distributions, use Oracle OpenJDK.

Set up the project JDK

If the necessary JDK is already defined in IntelliJ IDEA, select it from the SDK list.

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

Apply the changes and close the dialog.

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

If you build your project with Maven or Gradle, refer to Change the JDK version in a Maven project and Gradle JVM selection respectively for more information on how to work with JDKs.

Configure SDK documentation

You can add SDK documentation to IntelliJ IDEA so that you can get information about symbols and method signatures right from the editor in the Quick Documentation popup.

You can also configure external documentation by specifying the path to the reference information online. External documentation opens the necessary information in a browser so that you can navigate to related symbols and keep the information for further reference at the same time.

Specify SDK documentation paths

To view external SDK documentation, configure the documentation URL first.

Select the necessary SDK version if you have several SDKs configured, and open the Documentation Path tab on the right.

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

Apply the changes and close the dialog.

Access SDK documentation offline

If you work offline, you can view external documentation locally.

Download the documentation package of the necessary version.

The documentation package is normally distributed in a ZIP archive that you need to unpack once it is downloaded.

For example, you can download the official Java SE Development Kit 14.0.1 Documentation and unzip it.

Select the necessary JDK version if you have several JDKs configured, and open the Documentation Path tab on the right.

Click the How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij ideaicon and specify the directory with the downloaded documentation package (for example, C:\Users\jetbrains\Desktop\docs\api ).

Apply the changes and close the dialog.

When the documentation is configured, you can open it in the editor.

How to change java version in intellij idea

Generally, SDKs are global. It means that one SDK can be used in multiple projects and modules. After you create a new project and define an SDK for it, you can configure modules in this project to inherit its SDK. You can also specify an SDK for each module individually. For more information, refer to Change module SDK.

Supported SDKs

Define an SDK

Configure global SDKs

To add an SDK, click How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea, select the necessary SDK and specify its home directory in the dialog that opens.

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

Set up a project SDK

If the necessary SDK is already defined in IntelliJ IDEA, select it from the SDK list.

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

Set up a module SDK

If the necessary SDK is already defined in IntelliJ IDEA, select it from the Module SDK list.

If you want a module to inherit a project SDK, select the Project SDK option from the Module SDK list.

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

Java Development Kit (JDK)

To develop applications in IntelliJ IDEA, you need a Java SDK (JDK). A JDK is a software package that contains libraries, tools for developing and testing Java applications (development tools), and tools for running applications on the Java platform (Java Runtime Environment — JRE).

The JRE can be obtained separately from the JDK, but it’s not suitable for application development, as it doesn’t have essential components such as compilers and debuggers.

The bundled JRE is used for running the IDE itself, and it’s not sufficient for developing Java applications. Before you start developing in Java, download and install a standalone JDK build.

Due to the changes in the Oracle Java License, you might not have the rights to use Oracle’s Java SE for free. We recommend that you use one of the OpenJDK builds to avoid potential compliance failures.

In IntelliJ IDEA, you can download a JDK package right from the IDE, or you can manually download the necessary JDK distribution and define it in the IDE.

For a manual download, use any available distribution that you like, for example:

If you don’t know which distribution to choose, and you don’t have specific requirements that instruct you to use one of the existing distributions, use Oracle OpenJDK.

Set up the project JDK

If the necessary JDK is already defined in IntelliJ IDEA, select it from the SDK list.

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

Apply the changes and close the dialog.

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

If you build your project with Maven or Gradle, refer to Change the JDK version in a Maven project and Gradle JVM selection respectively for more information on how to work with JDKs.

Configure SDK documentation

You can add SDK documentation to IntelliJ IDEA so that you can get information about symbols and method signatures right from the editor in the Quick Documentation popup.

You can also configure external documentation by specifying the path to the reference information online. External documentation opens the necessary information in a browser so that you can navigate to related symbols and keep the information for further reference at the same time.

Specify SDK documentation paths

To view external SDK documentation, configure the documentation URL first.

Select the necessary SDK version if you have several SDKs configured, and open the Documentation Path tab on the right.

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

Apply the changes and close the dialog.

Access SDK documentation offline

If you work offline, you can view external documentation locally.

Download the documentation package of the necessary version.

The documentation package is normally distributed in a ZIP archive that you need to unpack once it is downloaded.

For example, you can download the official Java SE Development Kit 14.0.1 Documentation and unzip it.

Select the necessary JDK version if you have several JDKs configured, and open the Documentation Path tab on the right.

Click the How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij ideaicon and specify the directory with the downloaded documentation package (for example, C:\Users\jetbrains\Desktop\docs\api ).

Apply the changes and close the dialog.

When the documentation is configured, you can open it in the editor.

IntelliJ IDEA 13 uses Java 1.5 despite setting to 1.7

14 Answers 14

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

Please check your project/module language levels (Project Structure | Project; Project Structure | Modules | module-name | Sources). You might also want to take a look at Settings | Compiler | Java Compiler | Per-module bytecode version.

If nothing of this helps (my case), you can set it in your pom.xml, like this:

[For IntelliJ IDEA 2016.2]

I would like to expand upon part of Peter Gromov’s answer with an up-to-date screenshot. Specifically this particular part:

You might also want to take a look at Settings | Compiler | Java Compiler | Per-module bytecode version.

I believe that (at least in 2016.2): checking out different commits in git resets these to 1.5.

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

Alternatively, you can apply maven-compiler-plugin with appropriate java version by adding this to your pom.xml:

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

I tried making changes to Intellij IDEA as below:

but nothing worked, it reverted the versions to java 1.5 as soon as I saved it.

However, adding below lines to root(project level) pom.xml worked me to resolve above issue: (both of the options worked for me)

File->Project structure->Project Settings->Project->Project Language level

File->Project structure->Project Settings->Modules->Language level

Change level using drop down

In your command line(Unix terminal) Go to your project root folder, and do this

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

In IntelliJ Community Edition 2019.02, Changing the following settings worked for me

Update File->Project structure->Project Settings->Project->Project Language level to Java 11 (update to the java version that you wish to use in your project) using drop down.

Update File->Project structure->Project Settings->Modules->Language level

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

Second, do a full rebuild.

How to change java version in intellij idea. Смотреть фото How to change java version in intellij idea. Смотреть картинку How to change java version in intellij idea. Картинка про How to change java version in intellij idea. Фото How to change java version in intellij idea

It turned out I have remote repository setting in my maven’s settings.xml which the project depends on, but Intellij uses his own maven which doesn’t have same setting with my local maven.

One more thing that could cause this is having incorrect version of the

In my case it was pointing to a non-existing project and for some reason IntelliJ downgraded version in settings to 1.5 and later when I fixed it, it was still interpreting target code version as 5 (despite setting it to 11).

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *