Despite specifying JDK 1.7 in all project settings (including in File -> Project Structure -> Project :: Project SDK), the following error is produced by IntelliJ 13 when trying to compile some simple Java 7 code which does use the diamond operator:
java: diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
Is there any other place in the configuration where the expected -source 7 option should be enabled?
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.
Set also this:
File -> Project Structure -> Modules :: Sources (next to Paths and Dependencies) and that has a "Language level" option which also needs to be set correctly.
If nothing of this helps (my case), you can set it in your pom.xml, like this:
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
As this cool guy mentioned here:
https://stackoverflow.com/a/25888116/1643465
[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.
Alternatively, you can apply maven-compiler-plugin with appropriate java version by adding this to your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
I tried making changes to Intellij IDEA as below:
1.
File >> Settings >> Build, Execution, Deployment >> Compiler >> Java Compiler >> project bytecode version: 1.8 >> Per-module bytecode version: 1.8
2.
File >> Project Structure >> Project Settings >> Project >> SDK : 1.8, Project Language : 8 - Lambdas
File >> Project Structure >> Project Settings >> Modules >> abc : Language level: 8 - Lambdas
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)
Option 1:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Option 2:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
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
find . -type f -name '*.iml' -exec sed -i '' s/JDK_1_5/JDK_1_8/g {} +
This will change the language level property in all your project .iml files from java 1.5 to java 1.8.
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
Update File->Settings->Build,Execution,Deployment -> Compiler -> Java Compiler-> Project ByteCode Version to java 11.
Update Target version for all the entries under File->Settings->Build,Execution,Deployment -> Compiler -> Java Compiler-> Per module Byte Code Version.
First, you need to change the "project bytecode version" under File > Settings, Compiler > Java Compiler
Second, do a full rebuild.
I have same problem but with different situation. I can compile without any issue with maven in command line (mvn clean install), but in Intellij I always got "java: diamond operator is not supported in -source 1.5" compile error despite I have set the maven-compiler-plugin with java 1.8 in the pom.xml.
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.
So my solution was changing the Intellij's maven setting (Settings -> Build, execution, Deployment -> Maven -> Maven home directory) to use the local maven.
One more thing that could cause this is having incorrect version of the <parent> project.
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).
I managed to fix this by changing settings for new projects:
File -> New Projects Settings -> Settings for New Projects -> Java
Compiler -> Set the version
File -> New Projects Settings -> Structure for New Projects ->
Project -> Set Project SDK + set language level
Remove the projects
Import the projects
I had the following property working for me in IntelliJ 2017
<properties>
<java.version>1.8</java.version>
</properties>
There seems a few places that effect the source (byte code) version in IntelliJ:
• IntelliJ > Preferences >Build Exce Deploy > Java Compiler
◦ Module > Target Bytecode Version
• File > Project Structure
◦ Project > Language Level & SDK
◦ Module > Language Level
• Maven Properties
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
nothing from other answers helped, except of installing new Intellij Idea version
Related
When running a JUnit test, using IntelliJ IDEA, I get
How can I correct this?
Using SDK 1.7
Module language level is 1.7
Maven build works fine. (That's why I believe this in IDEA configuration issue)
Most likely you have incorrect compiler options imported from Maven here:
Also check project and module bytecode (target) version settings outlined on the screenshot.
Other places where the source language level is configured:
Project Structure | Project
Project Structure | Modules (check every module) | Sources
Maven default language level is 1.5 (5.0), you will see this version as the Module language level on the screenshot above.
This can be changed using maven-compiler-plugin configuration inside pom.xml:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
or
<project>
[...]
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
[...]
</project>
IntelliJ IDEA will respect this setting after you Reimport the Maven project in the Maven Projects tool window:
IntelliJ 15, 2016 & 2017
Similar to that discussed below for IntelliJ 13 & 14, but with an extra level in the Settings/Preferences panel: Settings > Build, Execution, Deployment > Compiler > Java Compiler.
IntelliJ 13 & 14
In IntelliJ 13 and 14, check the Settings > Compiler > Java Compiler UI to ensure you're not targeting a different bytecode version in your module.
In IntelliJ IDEA 14.1 the "Target bytecode version" is in a different place.
The following change worked for me:
File > Settings... > Build, Execution, Deployment > Compiler > Java Compiler : change Target bytecode version from 1.5 to 1.8
Have you looked at your build configuration it should like that if you use maven 3 and JDK 7
<build>
<finalName>SpringApp</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
...
</plugins>
...
</build>
I ran into this and the fix was to go to Project Settings > Modules > click on the particular module > Dependencies tab. I noticed the Module SDK was still set on 1.6, I changed it to 1.7 and it worked.
I've found required options ('target bytecode version') in settings > compiler > java compiler in my case (intelij idea 12.1.3)
Modify the compiler setting file of the project in the following path and change the 'target' to 1.7:
/project/.idea/compiler.xml
<bytecodeTargetLevel>
<module name="project-name" target="1.7" />
</bytecodeTargetLevel>
I resolved it by setting the field blank:
Settings > Compiler > Java Compiler > Project bytecode version
Than IntelliJ uses the JDK default version.
From one moment to the other I also got this error without a clear reason. I changed all kinds of settings on the compiler/module etc. But in the end I just recreated the IntelliJ project by reimporting the Maven project and the issue was solved. I think this is a bug.
IntelliJ 12 129.961
I've hit this after just minor upgrade from IntelliJ IDEA 14 to v14.1.
For me changing an edit of top/parent pom helped and then clicked re-import Maven (if it is not automatic).
But it maybe just enough to Right Click on module(s)/aggregated/parent module and Maven -> Reimport.
I resolved bellow method
File >> Project Structure >> Project >> Project Language Level
--> do set proper version (ex: 1.5)
check
.idea/misc.xml
sometimes you need to change languageLevel="JDK_1_X" attribute manually
If it is a Gradle project, in your build.gradle file, search for following settings:
sourceCompatibility = "xx"
targetCompatibility = "xx"
For all subrpojects, in your root build.gradle file, you may put:
subprojects { project ->
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
}
Although you can manually set language levels in Idea > Settings, if it is a Gradle project, Idea automatically synchronizes module .iml files from Gradle settings ( tested with Idea 15+). So all your manual changes are overriden when gradle is refreshed.
Based on Gradle documentation, if these are not set, then current JVM configuration is used.
I found another way to run into this error. You can get this if you have been re-organizing your directory structure, and one of your poms is pointing to the old parent which no-longer configures javac (because that configuration was moved to a middle level). If this happens the top level defaults to 1.5 and the misbehaving lower level pom inherits it.
So another thing to check when you see this error is that your pom structure is matching your directory structure properly.
If Maven build works fine, try to synchronizing structure of Maven and IntelliJ IDEA projects.
In the Maven tool window, click refresh button . On pressing this button, IntelliJ IDEA parses the project structure in the Maven tool window.
Note that this might not help if you're using EAP build, since Maven synchronization feature may be broken sometimes.
If all the previous solutions haven't worked for you (which was my case), you can delete intellij config files:
project_directory/.idea/compiler.xml
project_directory/.idea/encodings.xml
project_directory/.idea/misc.xml
project_directory/.idea/modules.xml
project_directory/.idea/vcs.xml
project_directory/.idea/workspace.xml
etc.
Intellij will regenerate new ones later.
However, BE CAREFUL, this will also delete all intellij configuration made on the projet (i.e: configuration of debug mode, ...)
You need to change Java compiler version in in build config.
Make sure right depency is selected.
File > Project Structure
Select your project and navigate to Dependencies tab. Select right dependancy from dropdown or create new.
I use IntelliJ IDEA as my development environment, and Maven for dependency management. I frequently build my project structure (directories, poms, etc) outside of IDEA and then import the project into IDEA using Import project from external model. This works great, except that in my poms I specify that the maven-compiler-plugin should use JDK 1.6, and when I import, IDEA informs me that the Language Level Changed and that Language level changes will take effect on project reload, and then prompts to reload the project. This is annoying because I always use the same JDK version.
How do I change the default JDK that IntelliJ IDEA uses, so that I don't have to reload my project every time I import a new project?
This setting is changed in the "Structure for New Projects" dialog. Navigate to "File" -> "New Projects Setup" -> "Structure..."
Next, modify the "Project SDK" and "Project Language Level" as appropriate.
Previous versions of IntelliJ IDEA had this setting in "File" -> "Other Settings" -> "Default Project Structure...".
IntelliJ IDEA 12 had this setting in "Template Project Structure..." instead of "Default Project Structure..."
Download and unpack a JDK archive file (.tar.gz) and add it as a SDK in the 'Project Structure' dialog box ( Ctrl+Alt+Shift+S )
click on the gif to enlarge
Also make sure to set an appropriate 'Project language level'. I forgot to do that when creating the GIF.
Project Structure > Project > Project language level
For Java 8 set it to 8, for Java 9 set it to 9, and so on.
I am using IntelliJ IDEA 14.0.3, and I also have same question. Choose menu File \ Other Settings \ Default Project Structure...
Choose Project tab, section Project language level, choose level from dropdown list, this setting is default for all new project.
I have found out that in recent versions of IntelliJ IDEA requires Java 1.8 but is not configured by default.
We can change the path or configure from Project Settings > Project > Project SDK
here we can edit or add the JDK´s path.
(in my case the path is located in C:\Program Files\Java\jdk1.8.0_102)
Change JDK version to 1.8
Language level File -> project Structure -> Modules -> Sources -> Language level -> 8-Lambdas, type annotations etc.
Project SDk File -> project Structure -> Project 1.8
Java compiler File -> Settings -> Build, Executions, Deployment -> Compiler -> Java compiler
One other place worth checking: Look in the pom.xml for your project, if you are using Maven compiler plugin, at the source/target config and make sure it is the desired version of Java. I found that I had 1.7 in the following; I changed it to 1.8 and then everything compiled correctly in IntelliJ.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
The above responses were very useful, but after all settings, the project was running with the wrong version. Finally, I noticed that it can be also configured in the Dependencies window.
Idea 2018.1.3 File -> Project Structure -> Modules -> Sources and Dependencies.
To change the JDK version of the Intellij-IDE himself:
Start the IDE -> Help -> Find Action
than type:
Switch Boot JDK
or (depend on your version)
Switch IDE boot JDK
For latest version intellij, to set default jdk/sdk for new projects go to
Configure->Structure for New Projects -> Project Settings -> Project SDK
I am using IntelliJ 2020.3.1 and the File > Other Settings... menu option has disappeared. I went to Settings in the usual way and searched for "jdk". Under Build, Execution, Deployment > Build Tools > Maven > Importing I found the the setting that will solve my specific issue:
JDK for importer.
On my linux machine I use a script like this:
export IDEA_JDK=/opt/jdk14
/idea-IC/bin/idea.sh
This question already has answers here:
Error:java: javacTask: source release 8 requires target release 1.8
(25 answers)
Closed 4 years ago.
I have opened git project I was running under Eclipse previously in IntelliJ. I have changed to Java 8 in following places:
File -> Project Structure -> SDKs
and
File -> Project Structure -> Project
Where to set Java 8 else? What it wants?
The project is Maven, pom file has only dependencies sections
UPDATE
I am trying to run under IntelliJ
In order to compile your code you should add maven build section:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Also you can go to File | Settings | Build, Execution, Deployment | Compiler | Java Compiler and change it there, but it will cause other developers failures as they need to modify IDE before build
In addition to what you have done, you also have to update the build Module.
SHIFT + CTRL + ALT + S -> Modules -> Select JDK 1.8 and press apply
Check the output from your build to make sure that IntelliJ is using JDK 8 and not the earlier version (7?) which you had.
You can try this way:
For Eclipse:
Windows -> Preferences -> Java -> Installed JREs -> add JDK
You can download the JDK for 1.8 and browse the file when you are trying to add JDK. If it's windows OS then you need to install Java 1.8 and then use the path from C:\Program Files\...\jdk1.8 (Please refer this for reference)
The above is for setting eclipse.
Then you need to apply changes for the project setup as below:
Project -> Properties -> Java Build Path -> Libraries -> Click on JRE System Library -> Edit button -> change the Library as 8 that you have set up for eclipse
For IntelliJ, you can try this guide
I'm using java 1.7 in intellij and it's giving me a compile error as if I'm using pre-1.7. Saying, "Incompatible type. Found 'java.lang.String'. required 'byte, char, short, or int'.
I'm rattling my brain trying to figure out why this is. Thanks
You need to change language level in your IDE.
Check these settings:
File > Project Structure > Project > Project SDK
File > Project Structure > Project > Project Language Level
File > Project Structure > Modules > Your module > Sources > Language Level
File > Project Structure > Modules > Your module > Dependencies > Module SDK
Also check compiler settings. Sometimes it adds extra arguments to compiler:
File > Settings > Compiler > Java Compiler > Byte code version
If you use maven plugin enable auto-import. Then the language level will be detected automatically from your pom.xml settings.
In your project settings most probably you use java compiler java 1.6 or prior.
Change that to java 1.7
I think you have installed multiple JDKs on your system or you are using the default JDK that is bundled with IDE intellij. Try this link to change your JDK path to the one that is 1.7 or higher if any installed on your system
or update your JDK to the latest version available
I solved my case like this:
Intellij
File -> Project Structure -> Project -> Project language level:
And in the options box I selected the option:
14 - Switch expressions
If you add this to your pom.xml file it will resolve the issue where the key part is the source 1.8:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
When running a JUnit test, using IntelliJ IDEA, I get
How can I correct this?
Using SDK 1.7
Module language level is 1.7
Maven build works fine. (That's why I believe this in IDEA configuration issue)
Most likely you have incorrect compiler options imported from Maven here:
Also check project and module bytecode (target) version settings outlined on the screenshot.
Other places where the source language level is configured:
Project Structure | Project
Project Structure | Modules (check every module) | Sources
Maven default language level is 1.5 (5.0), you will see this version as the Module language level on the screenshot above.
This can be changed using maven-compiler-plugin configuration inside pom.xml:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
or
<project>
[...]
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
[...]
</project>
IntelliJ IDEA will respect this setting after you Reimport the Maven project in the Maven Projects tool window:
IntelliJ 15, 2016 & 2017
Similar to that discussed below for IntelliJ 13 & 14, but with an extra level in the Settings/Preferences panel: Settings > Build, Execution, Deployment > Compiler > Java Compiler.
IntelliJ 13 & 14
In IntelliJ 13 and 14, check the Settings > Compiler > Java Compiler UI to ensure you're not targeting a different bytecode version in your module.
In IntelliJ IDEA 14.1 the "Target bytecode version" is in a different place.
The following change worked for me:
File > Settings... > Build, Execution, Deployment > Compiler > Java Compiler : change Target bytecode version from 1.5 to 1.8
Have you looked at your build configuration it should like that if you use maven 3 and JDK 7
<build>
<finalName>SpringApp</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
...
</plugins>
...
</build>
I ran into this and the fix was to go to Project Settings > Modules > click on the particular module > Dependencies tab. I noticed the Module SDK was still set on 1.6, I changed it to 1.7 and it worked.
I've found required options ('target bytecode version') in settings > compiler > java compiler in my case (intelij idea 12.1.3)
Modify the compiler setting file of the project in the following path and change the 'target' to 1.7:
/project/.idea/compiler.xml
<bytecodeTargetLevel>
<module name="project-name" target="1.7" />
</bytecodeTargetLevel>
I resolved it by setting the field blank:
Settings > Compiler > Java Compiler > Project bytecode version
Than IntelliJ uses the JDK default version.
From one moment to the other I also got this error without a clear reason. I changed all kinds of settings on the compiler/module etc. But in the end I just recreated the IntelliJ project by reimporting the Maven project and the issue was solved. I think this is a bug.
IntelliJ 12 129.961
I've hit this after just minor upgrade from IntelliJ IDEA 14 to v14.1.
For me changing an edit of top/parent pom helped and then clicked re-import Maven (if it is not automatic).
But it maybe just enough to Right Click on module(s)/aggregated/parent module and Maven -> Reimport.
I resolved bellow method
File >> Project Structure >> Project >> Project Language Level
--> do set proper version (ex: 1.5)
check
.idea/misc.xml
sometimes you need to change languageLevel="JDK_1_X" attribute manually
If it is a Gradle project, in your build.gradle file, search for following settings:
sourceCompatibility = "xx"
targetCompatibility = "xx"
For all subrpojects, in your root build.gradle file, you may put:
subprojects { project ->
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
}
Although you can manually set language levels in Idea > Settings, if it is a Gradle project, Idea automatically synchronizes module .iml files from Gradle settings ( tested with Idea 15+). So all your manual changes are overriden when gradle is refreshed.
Based on Gradle documentation, if these are not set, then current JVM configuration is used.
I found another way to run into this error. You can get this if you have been re-organizing your directory structure, and one of your poms is pointing to the old parent which no-longer configures javac (because that configuration was moved to a middle level). If this happens the top level defaults to 1.5 and the misbehaving lower level pom inherits it.
So another thing to check when you see this error is that your pom structure is matching your directory structure properly.
If Maven build works fine, try to synchronizing structure of Maven and IntelliJ IDEA projects.
In the Maven tool window, click refresh button . On pressing this button, IntelliJ IDEA parses the project structure in the Maven tool window.
Note that this might not help if you're using EAP build, since Maven synchronization feature may be broken sometimes.
If all the previous solutions haven't worked for you (which was my case), you can delete intellij config files:
project_directory/.idea/compiler.xml
project_directory/.idea/encodings.xml
project_directory/.idea/misc.xml
project_directory/.idea/modules.xml
project_directory/.idea/vcs.xml
project_directory/.idea/workspace.xml
etc.
Intellij will regenerate new ones later.
However, BE CAREFUL, this will also delete all intellij configuration made on the projet (i.e: configuration of debug mode, ...)
You need to change Java compiler version in in build config.
Make sure right depency is selected.
File > Project Structure
Select your project and navigate to Dependencies tab. Select right dependancy from dropdown or create new.