When running a JUnit test, using IntelliJ IDEA, I get
How can I correc
I resolved bellow method
File >> Project Structure >> Project >> Project Language Level --> do set proper version (ex: 1.5)
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.
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.
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.
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>
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:
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: