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
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
Related
i have work with Intellij a java spring project
these error appear to me when i build and run the project :
cannot resolve symbol 'springframework'
Error:(32, 48) java: diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
Error:(33, 55) java: method references are not supported in -source 1.5
(use -source 8 or higher to enable method references)
i have search about similar question but not working with me
i have try:
invalidate cache and re import to maven dependencies but still gave and error
my java version: javac 1.8.0_111
maven error:
and upload the error log file to drive
Maybe the problem with Maven. Either update or add maven-compiler-plugin plugin in your pom.xml.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>//version_number</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build
In project structure, under Modules inside Dependencies, Module SDK should be mapped to your java 8.
This question already has answers here:
maven. lambda expressions are not supported in -source 1.5
(3 answers)
Closed 5 years ago.
i am using Java 1.8.101 version. when i run maven clean install, at that time i am getting error
strings in switch are not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable strings in switch).
I don't know why because already i am using java 1.8.101 version.\
Any help would be great.
Thanks a lot in advance for help.
Attached screenshot.
As already suggested by #Jeremy as well, make an entry to the pom.xml file as -
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
and use mvn clean install on the command line to verify the change.
I have a maven project. In the pom.xml file the following is stated:
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
...
</plugins>
</build>
...
AFAIK this is correct, it should build against JDK 7.
I run a Debian based Linux dist and when I do mvn clean install it seems to always build against the javac version I have set in my os.
I've tried reading up on what the plugin exactly does https://maven.apache.org/plugins/maven-compiler-plugin/, but it doesn't really state how.
An example is I have javac 8 running on my os. When I invoke mvn clean install, the project compiles against JDK 8 and not JDK 7 as stated in the pom.xml. Why is this?
By default the maven-compiler-plugin uses %JAVA_HOME%/bin/javac to compile, unless:
you set the executable-parameter to a different location
you use Toolchains, which seems to match your requirements, i.e a different Java Runtime for Maven compared to the JDK for the maven-compiler-plugin.
Source and target settings are just passed to the javac compiler as parameters. The javac installed on the machine is used.
Is it possible to force the gmaven plugin to use a different JDK than the one specified in JAVA_HOME? We need to build a specific project using Java 7, but most developers will have JAVA_HOME set to a Java 6 install as all our other projects are still on Java 6.
The error message we get is:
[ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.4:generateStubs (default) on project XYZ: Execution default of goal org.codehaus.gmaven:gmaven-plugin:1.4:generateStubs failed: An API incompatibility was encountered while executing org.codehaus.gmaven:gmaven-plugin:1.4:generateStubs: java.lang.UnsupportedClassVersionError: <snip> : Unsupported major.minor version 51.0
Thanks!
The Maven Enforcer plugin is an easy way to require a specific JDK version.
you can specify JAVA_HOME for maven task in ide or bat/sh file for example
Intellige Idea
and no need to change system environment variables
Example configuration from maven-compiler-plugin
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
The maven by default uses Java 1.4, not the Java set in the JAVA_HOME variable.
You can set an alternate jdk in the maven-complier-plugin configuration. See here
I work on a Java program that should be compatibe with Java 5. I had #Override annotations on implemented interface methods which is allowed in Java 6, but not in 5. I use a Java 6 SDK. Eclipse correctly gives error messages on the #Override when I set it to 5.0 compliance. My Maven build, however, runs without even a warning, using the following settings in my POM:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
Am I correct in expecting that this should actually make the build fail? Why doesn't it, and is there something I can do?
This is actually a JDK problem, not a Maven problem. The #Override annotation is not failing with a -source 1.5 flag to to a 1.6 javac. Go ahead and try it. The only way to make it fail, is, unfortunately, to use a 1.5 javac.
Sorry, HTH.
EDIT
I ran into this problem myself, and I also wondered if it's actually looking at the setting in the pom. Turning on debug output (-X I believe, was a while ago) will print the javac command line to the standard output, and you'll see that it is indeed using the -source 1.5 parameter.
As roe's answer says you need to use a 1.5 compiler because the JDK isn't doing its job quite right. It's worth pointing out that you can avoid messing about with paths etc. by tweaking the maven-compiler-plugin configuration to use a specific compiler:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_1_5_HOME}/bin/javac</executable>
<compilerVersion>1.5</compilerVersion>
</configuration>
</plugin>
...
</plugins>
You can then specify the path to the compiler in your project or settings.xml
<properties>
<JAVA_1_5_HOME>/path/to/1.5jdk</JAVA_1_5_HOME>
</properties>