Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Java by (3.4k points)

When running a JUnit test, using IntelliJ IDEA, I get

enter image description here

How can I correct this?

  • Using SDK 1.7
  • The module language level is 1.7

Maven build works fine. (That's why I believe this in IDEA configuration issue)

1 Answer

0 votes
by (46k points)

I think you have the wrong compiler options carried from Maven here:

image

Additionally, verify project and module bytecode (mark) version settings marked on the screenshot.

Other places where the source language level is configured:

  • Project Structure | Project

image

  • Project Structure | Modules (verify every module) | Sources

image

Maven default language level is 1.5 (5.0), you will notice this version as the Module language level on the screenshot preceding.

This can be modified 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>

 

<project> [...] <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> [...] </project>

IntelliJ IDEA will recognize this setting after you Reimport the Maven project into the Maven Projects tool window:

image

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Sep 26, 2019 in Java by Shubham (3.9k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...