AEM as Cloud Build Failure | Community
Skip to main content
jezwn
Level 5
December 20, 2023
Solved

AEM as Cloud Build Failure

  • December 20, 2023
  • 3 replies
  • 2009 views

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>
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

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

3 replies

ibishika
Level 4
December 20, 2023

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

jezwn
jezwnAuthor
Level 5
December 20, 2023

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

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
December 20, 2023

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
joerghoh
Adobe Employee
Adobe Employee
December 22, 2023