Expand my Community achievements bar.

SOLVED

AEM as Cloud Build Failure

Avatar

Level 6

Why is it getting error using Java 11?

07:50:40,543 [main] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project product100.core: Fatal error compiling: invalid target release: 11 -> [Help 1]

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Please check https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html 

Note:
 Merely setting the target option does not guarantee that your code actually runs on a JRE with the specified version. The pitfall is unintended usage of APIs that only exist in later JREs which would make your code fail at runtime with a linkage error. To avoid this issue, you can either configure the compiler's boot classpath to match the target JRE, or use the Animal Sniffer Maven Plugin to verify your code doesn't use unintended APIs, or better yet use the release option supported since JDK 9. In the same way, setting the source option does not guarantee that your code actually compiles on a JDK with the specified version. To compile your code with a specific JDK version, different than the one used to launch Maven, refer to the Compile Using A Different JDK example.

 

Use release option instead source and target



Arun Patidar

View solution in original post

4 Replies

Avatar

Level 6

Hi @jezwn ,

 

Please check if JAVA_HOME is set correctly. 

 

Please also run the below command:

mvn --version

 

Check if maven is pointing the correct Java version.

 

Thanks,

Ishika B

Avatar

Level 6

This is AEM Cloud sandbox instance I'm talking about. It works fine locally.

Avatar

Correct answer by
Community Advisor

Please check https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html 

Note:
 Merely setting the target option does not guarantee that your code actually runs on a JRE with the specified version. The pitfall is unintended usage of APIs that only exist in later JREs which would make your code fail at runtime with a linkage error. To avoid this issue, you can either configure the compiler's boot classpath to match the target JRE, or use the Animal Sniffer Maven Plugin to verify your code doesn't use unintended APIs, or better yet use the release option supported since JDK 9. In the same way, setting the source option does not guarantee that your code actually compiles on a JDK with the specified version. To compile your code with a specific JDK version, different than the one used to launch Maven, refer to the Compile Using A Different JDK example.

 

Use release option instead source and target



Arun Patidar