I want to run tests with different java version than my source java version
Answered
My main source has java version 7
I want to use java 8 from my tests. so i updated the compiler plugin to
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>7</source>
<target>7</target>
<testSource>8</testSource>
<testTarget>8</testTarget>
</configuration>
</plugin>
This way I can use java 8 features in unit tests. This works fine when i run the tests using maven from commandline.
But when i run the test directly from intellij, it throughs error saying 'lambda expressions are not supported in source 7'
looks like it use the same source version for tests.
How do i configure Intellij to use different java version for tests
Please sign in to leave a comment.
Hello,
Unfortunately, it is not supported at the moment.
We hope to add support for this configuration in one of the future updates. Related feature request on our issue tracker: IDEA-85478. Feel free to follow it for updates.
A workaround that you can try:
There's a workaround to force Idea to use the language level defined in
<testSource>when importing Maven project. You can create a separate Maven profile only for Idea with different compiler plugin settings:It will unblock developers of libraries who need to target JRE 1.6 but want to use 1.8 in unit tests.