Maven invalid target release: 13 - java

I'm using Maven in Eclipse and i want to run my project with Java13. Every time i build my project i get the following error message:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project subscriptionsmanager: Fatal error compiling: invalid target release: 13 -> [Help 1]
I've configured my pom.xml file inside <properties> as follows:
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>13</maven.compiler.source>
<maven.compiler.target>13</maven.compiler.target>
and Java13 as JRE from Eclipse from Eclipse "Java Build Path" section.
Is there any settings that I have not considered?

As naman suggested, you'll need to explicitly configure your maven compiler plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>13</source>
<target>13</target>
</configuration>
</plugin>
...

In addition to the above post, you can also directly mention the release in configuration.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>

Related

migrating from using jdk8 to jdk11, getting errors related to tools.jar

I am migrating an project from jdk8 to jdk11.
in my pom.xml file, i have put
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<java.version>11</java.version>
and
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.11</source>
<target>1.11</target>
<release>11</release>
<fork>true</fork>
</configuration>
</plugin>
after running mvn clean install command, i am getting an error: Could not find artifact jdk.tools:tools:jar:1 at specified path /opt/jdk-11.0.9/../lib/tools.jar. I am aware that tools.jar is removed from jdk11. I am thinking some dependencies in my pom.xml are relying on the tools.jar, and I have not find a good solution to figure out what these dependencies are. Or It could be some other issues.
based on your above config, it is expected to get the following error:
Fatal error compiling: error: invalid target release: 1.11
I would recommend το change the source and release targets to be settled 11 not 1.11, see the example below.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
Then using mvn dependency:tree and mvn dependency:analyze and/or using -Xoption to debug it.

Cannot prepare the release because you have local modifications :

I am trying to do a Maven realeas prepare but this error keeps happening
I tried to execlude the root pom from being checked but it goes now to the other poms
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:prepare (default-cli) on project sfg-pet-clinic: Cannot prepare the release because you h
ave local modifications :
[ERROR] [pet-clinic-data/pom.xml:modified]
[ERROR] [pet-clinic-web/pom.xml:modified]
and this is an example of my root pom :
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<goals>install</goals>
<checkModificationExcludes>
<checkModificationExclude>pom.xml</checkModificationExclude>
</checkModificationExcludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<scm>
<developerConnection>scm:git:https://github.com/OmarSharif93/sfg-pet-clinic.git</developerConnection>
</scm>
what can I do to resolve this ?
I Committed the pom.xml and it solved the problem.

Configure maven-compiler-plugin so it works both with JDK-8 and JDK-12 (in Spring Boot project)

Is it possible to configure maven-compiler-plugin so it works both with JDK 8 and JDK 12? I am not sure if it is relevant, but it is a Spring Boot project.
1. The configuration
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<release>8</release>
</configuration>
</plugin>
is compilable under JDK-12, but under JDK-8 fails:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project xxxx:
Fatal error compiling: invalid flag: --release
2. The configuration
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
which misses the <release>8</release> parameter is compilable under JDK-8, but under JDK-12 fails:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project xxxx:
Fatal error compiling: CompilerException: NullPointerException
All the possible internet sources I found advice to use the <release>8</release> parameter to be able to avoid the error under JDK-12, but this disables the compilability under JDK-8.
Our source and target compatibility is Java 8, and we need to build the code with the good old plain mvn clean install (without providing a profile!) on the developers' machines with JDK-12, but also on Jenkins, where we still have to keep JDK-8, and we also have some conservative developers :)
first you should define the maven-compiler-plugin within the pluginManagement like this:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<...>
...
and furthermore using profile which are automatically activated which looks like this:
<profiles>
<profile>
<id>jkd-12-compile</id>
<activation>
<jdk>12</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>8</release>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<id>jdk-8-compile</id>
<activation>
<jdk>[,8]</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
One not usually a mvn clean install is not needed. You usually only need mvn clean verify...
A tad simpler solution relies on using the properties rather than the explicit configuration entries. It won't complain for anything that it doesn't support.
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<profiles>
<profile>
<id>jdk9+</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<properties>
<maven.compiler.release>8</maven.compiler.release>
</properties>
</profile>
</profiles>
Enjoy!

Maven build fails with os-maven-plugin

I added the os-maven-plugin to my pom like so:
<build>
<extensions>
<!-- native platform classifier -->
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.5.0.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
</plugin>
<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>
On my dev machine I can compile and run this project just fine, however when I try to run the build via Jenkins it fails immediately and shows this error in the logs:
[INFO] Internal error in the plugin manager getting plugin
'org.apache.maven.plugins:maven-clean-plugin': Plugin
'org.apache.maven.plugins:maven-clean-plugin:2.5' has an invalid descriptor:
1) Plugin's descriptor contains the wrong group ID: kr.motd.maven
2) Plugin's descriptor contains the wrong artifact ID: os-maven-plugin
3) Plugin's descriptor contains the wrong version: 1.5.0.Final
Clearly, it seems to be using the descriptors from the os-maven-plugin to get the clean-plugin and fails because the descriptors don't match up for that plugin.
Why is this and how should I be incorporating the os-maven-plugin into my project?

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>

Categories