project compile error release 8 requires target 1.8 release - java

I have an error Error:java: javacTask: source release 8 requires target release 1.8. I use 1.8 java, language level set to 8. The only thing I guess could be the reason is the line in the pom.xml file
<configuration>
<executable>${java.home}/bin/java</executable>
<commandlineArgs>${runfx.args}</commandlineArgs>
</configuration>
here the line
<commandlineArgs>${runfx.args}</commandlineArgs>
is red and what to do with this I can't manage to get.

To set the compiler version in Maven, you would have something that looks like this in your pom.xml file:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
3.3 is the latest Maven Compiler Plugin version. I assumed it was needed for Java 8 support.
This is the same as setting the -source and -target compiler options.

Related

class file version is not the same java.version in Eclipse maven

Here is my pom.xml.
As you see , I have the source/target set as 1.6 in maven compiler plugin . While my project property is set as java 1.7.
When i run mvn compile and then check the java class version via javap, i see a version number =51 which indicate the jre1.7.
Do i miss anything here ?
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>UTF-8</encoding>
<compilerVersion>1.6</compilerVersion>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<plugins>

Maven update resets Java version

Everytime I modify the dependencies inside the pom.xml file in my IntelliJ Maven project, the Java version is set to 1.5 and I have to receonfigure my project.
The following settings are modified by Maven:
Settings | Compiler | Java Compiler -> Target bytecode version
And Project Settings | Modules -> Language Level
Why is this happening and what do I have to do, so that maven doesn't vandalise my settings?
You have to explicitely set the java version in your pom file so that version 1.5 doesn't get set by default.
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
Specify the java version under properties.
<properties>
<java-version>1.8</java-version>
</properties>
and to use the same version with maven compile or package then include the same version in compile plug-in
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

Eclipse - Maven project changing source compliance

I have a mid-size project in java eclipse, in which all dependencies were being manually imported into the build path. For the sake of sanity, I wanted to convert it to a maven project.
The problem is: I had the source level/jre defined for 1.8 and when i converted to a maven project, It switched to the default of 1.5.
I tried some answers around SO for forcing the source compliance in maven to 1.8 but it didn't work.
I added to the
<build>
<plugins>
<plugin>
<groupId>[project group id]</groupId>
<artifactId>[project artifact id]</artifactId>
<version>0.0.1-SNAPSHOT</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Is anything missing here?
EDIT1: Forget me, I'm bad. The correct version is:
<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>
after this you need these two
preference - > java - > compiler - > 1.8 and language level to 8
preference - > java -> installed JRE -> JDK 1.8

Maven javacTask: source release 1.7 requires target release 1.7

When I try building my Java project using Maven, I'm getting the following error:
javacTask: source release 1.7 requires target release 1.7
In my pom file, I have defined source and target for 1.7.
<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>
However, when using the maven plugin in Eclipse, I do not run into this error and my code builds without any errors. I'm thinking this is due to something particular to Maven itself on my local machine. Any ideas what could be the root cause of this?

FindBugs: How can I run it in Java 5 mode?

When I run FindBugs on my project via Maven, I get lots of these:
Can't use annotations when running in JDK 1.4 mode!
How do I fix that? Couldn't find anything in the manual.
I believe you are missing the targetJdk element in the plugin configuration, like in below snippet.
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.0.1</version>
<configuration>
<targetJdk>1.5</targetJdk>
</configuration>
</plugin>
</plugins>
</reporting>
Make sure your Maven build plugin is compiling to 1.5, and not 1.4.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>

Categories