Xetius
Xetius

Reputation: 46904

Problems running Java 8 TestNG inside IntelliJ

I am writing a Maven application using OpenJDK 1.8 and running tests using TestNG.

When I run Maven from the command line everything works fine, but when I try to run the test inside IntelliJ, then the make process is displaying the following error:

java: javacTask: source release 8 requires target release 1.8

I have the project settings pointing to the 1.8 JDK and Project Language Level 8.

Inside Maven I have the following block (which I am guessing is not getting called yet as it seems to be the make causing the problem)

  <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>
    </configuration>
  </plugin>

I have even configured the Maven Runner JRE to point to the 1.8 JDK.

I just don't seem to be able to get IntelliJ 12.0.4 to run the tests properly

Am I missing something?

Upvotes: 22

Views: 13664

Answers (4)

fragorl
fragorl

Reputation: 1736

For me, I needed to go File > Project Structure > Modules. Half of my modules had their "module SDK" field set to the wrong thing (not Project Default as they should have been).

Upvotes: 0

Xetius' answer didn't work for me in IntelliJ 14.1.2

In the end I found the section in .idea/misc.xml

<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
   <output url="file://$PROJECT_DIR$/out" />
</component>

I ended up with:

<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
    <output url="file://$PROJECT_DIR$/out" />
</component>

Upvotes: 2

user3024188
user3024188

Reputation: 71

There is another way to make it. Go to Files->Other Settings->Type "javac" in the search bar -> change the JDK default to "1.8" or any version you target.

Upvotes: 7

Xetius
Xetius

Reputation: 46904

After the hint from CrazyCoder it turns out that .idea/compiler.xml had the following section in it

<bytecodeTargetLevel> 
    <module name="game" target="1.7" /> 
</bytecodeTargetLevel> 

I changed this to:

<bytecodeTargetLevel> 
    <module name="game" target="1.8" /> 
</bytecodeTargetLevel> 

and it worked

Upvotes: 73

Related Questions