0

I wrote a benchmark using JMH and when building I get the following a compilation failure

lambda expressions are not supported in -source 1.6
[ERROR] (use -source 8 or higher to enable lambda expressions)

JAVA_HOME is set to jdk1.8_40. I have tried changing target and source in the pom.xml in jmh source folder jmh-core :

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <compilerVersion>1.8</compilerVersion>
                <source>1.8</source>
                <target>1.8</target>
                <compilerArgument>-proc:none</compilerArgument>
            </configuration>
        </plugin>

But I still get the same error

Bionix1441
  • 2,135
  • 1
  • 30
  • 65
  • 1
    In jmh-core? Run maven with -X to see which target/javac is selected. – uraimo Apr 07 '15 at 15:32
  • The compiler version is still 1.6, compilerVersion = 1.6. source = 1.6 and target = 1.6 . I don't know where can I change that ? – Bionix1441 Apr 07 '15 at 15:37
  • 1
    I'd double check your javahome with echo $JAVA_HOME assuming you are on linux and add that source/target configuration to the pom of your project, i didn't understand that reference to jmh-core, are you trying to compile that library or your project with a dependency on jmh? – uraimo Apr 07 '15 at 15:46
  • I just have changed the source and target to 1.8 in pom.xml of my project, and I don't get the compilation failure anymore. – Bionix1441 Apr 07 '15 at 15:50
  • I was trying to change in jmh sources since the pom.xml of the benchmark is generated automatically. – Bionix1441 Apr 07 '15 at 15:57

1 Answers1

2

Are you using a Mac? If so, java 6 is already installed. I recommend just removing it from /System/Library/Java/JavaVirtualMachines/ .

Regardless, check java -version to see what jdk version is being used. Then type mvn -version on the command line. Is it pointed to java 6? If so, add the following to your ~/.mavenrc:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/{jdk-version}/Contents/Home

Where jdk-version would be your version of java 8

Derek_M
  • 1,018
  • 10
  • 22
  • I am using Linux, the environment variables JAVA_HOME and PATH are correctly set to jdk8. – Bionix1441 Apr 07 '15 at 15:44
  • where can I find ~/.mavenrc ? – Bionix1441 Apr 07 '15 at 16:11
  • From the home directory in the console, type vim ~/.mavenrc (or replace vim with your favorite tool.) It will probably be empty. – Derek_M Apr 07 '15 at 16:14
  • 1
    Yep, then add the export there. – Derek_M Apr 07 '15 at 16:16
  • The jdk is probably not installed in that path. I forgot that you are using linux. I think you can find where java is installed by typing 'which java' in the command line. There could also be a couple of issues, check out http://stackoverflow.com/questions/27319495/error-java-home-is-not-defined-correctly-executing-maven and http://www.veryant.com/support/phpkb/question.php?ID=91 – Derek_M Apr 07 '15 at 16:41