Java 21: The build is successful locally, but the following error occurs when updating the Java version on AEM Cloud | Community
Skip to main content
Nilesh_Mali
Level 3
April 14, 2025
Solved

Java 21: The build is successful locally, but the following error occurs when updating the Java version on AEM Cloud

  • April 14, 2025
  • 5 replies
  • 2966 views

[BUILD] Running maven build command(s)
Using Java version 21 from .cloudmanager/java-version.
Executing command mvn --batch-mode org.apache.maven.plugins:maven-dependency-plugin:3.1.2:resolve-plugins
06:49:47,547 [main] [INFO] Scanning for projects...

...

...

06:51:04,568 [main] [INFO] Toolchain in maven-compiler-plugin: JDK[/usr/lib/jvm/jdk-11.0.22]
06:51:04,608 [main] [INFO] Changes detected - recompiling the module! :source
06:51:04,610 [main] [INFO] Compiling 450 source files with javac [forked debug release 21] to target/classes
06:51:05,021 [main] [INFO] -------------------------------------------------------------
06:51:05,021 [main] [ERROR] COMPILATION ERROR :
06:51:05,021 [main] [INFO] -------------------------------------------------------------
06:51:05,021 [main] [ERROR] error: release version 21 not supported
06:51:05,021 [main] [INFO] 1 error
06:51:05,022 [main] [INFO] -------------------------------------------------------------

 

 

Best answer by SantoshSai

Hi @nilesh_mali 

You're seeing this error in your AEM Cloud Manager pipeline because your maven-compiler-plugin is configured to use --release 21, but Maven is picking up JDK 11 instead of JDK 21, despite Cloud Manager setting Java 21 (.cloudmanager/java-version).

Here’s the key error:

[ERROR] error: release version 21 not supported​

And this:

Toolchain in maven-compiler-plugin: JDK[/usr/lib/jvm/jdk-11.0.22]

indicates it's still using JDK 11, not 21.


Solution

Cloud Manager provides JDK 21, but Maven uses toolchains to decide which JDK to compile with. You need to explicitly configure a toolchains.xml file.

How can you Fix

  1. Create or update a .cloudmanager/config.yaml file (if you don’t already have one) and make sure it includes: java-version: "21"

  1. Provide a proper toolchains.xml in your repo root or .cloudmanager folder with JDK 21 config.

Here’s an example toolchains.xml:

<toolchains> <toolchain> <type>jdk</type> <provides> <version>21</version> <vendor>oracle</vendor> </provides> <configuration> <jdkHome>/opt/java/openjdk-21</jdkHome> </configuration> </toolchain> </toolchains>

Make sure /opt/java/openjdk-21 is the correct path on Cloud Manager (it usually is for Java 21).


Hope that helps you!

Regards,

Santosh

5 replies

arunpatidar
Community Advisor
Community Advisor
April 14, 2025
muskaanchandwani
Adobe Employee
Adobe Employee
April 14, 2025

@nilesh_mali 

Though Java 21 is available in AEM Cloud (as per .cloudmanager/java-version), the Maven build is still using JDK 11 when compiling - the maven-compiler-plugin is using a Java 11 toolchain as per trace you shared :

Toolchain in maven-compiler-plugin: JDK[/usr/lib/jvm/jdk-11.0.22]

You should configure the toolchain to use Java 21

SantoshSai
Community Advisor
SantoshSaiCommunity AdvisorAccepted solution
Community Advisor
April 15, 2025

Hi @nilesh_mali 

You're seeing this error in your AEM Cloud Manager pipeline because your maven-compiler-plugin is configured to use --release 21, but Maven is picking up JDK 11 instead of JDK 21, despite Cloud Manager setting Java 21 (.cloudmanager/java-version).

Here’s the key error:

[ERROR] error: release version 21 not supported​

And this:

Toolchain in maven-compiler-plugin: JDK[/usr/lib/jvm/jdk-11.0.22]

indicates it's still using JDK 11, not 21.


Solution

Cloud Manager provides JDK 21, but Maven uses toolchains to decide which JDK to compile with. You need to explicitly configure a toolchains.xml file.

How can you Fix

  1. Create or update a .cloudmanager/config.yaml file (if you don’t already have one) and make sure it includes: java-version: "21"

  1. Provide a proper toolchains.xml in your repo root or .cloudmanager folder with JDK 21 config.

Here’s an example toolchains.xml:

<toolchains> <toolchain> <type>jdk</type> <provides> <version>21</version> <vendor>oracle</vendor> </provides> <configuration> <jdkHome>/opt/java/openjdk-21</jdkHome> </configuration> </toolchain> </toolchains>

Make sure /opt/java/openjdk-21 is the correct path on Cloud Manager (it usually is for Java 21).


Hope that helps you!

Regards,

Santosh

Santosh Sai
Nilesh_Mali
Level 3
April 17, 2025

Thank you for support, Its working after adding above changes, additionally I added  build is executed with Java21.

Thank you for your support. It's working after applying the above changes. Additionally I added below plugin and I made sure the build is executed using Java 21.

 

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-toolchains-plugin</artifactId> <version>1.1</version> <executions> <execution> <goals> <goal>toolchain</goal> </goals> </execution> </executions> <configuration> <toolchains> <jdk> <version>21</version> <vendor>Oracle</vendor> </jdk> </toolchains> </configuration> </plugin>

  

Level 3
August 1, 2025

@nilesh_mali 

Please remove entire toolchain plugin part from your main pom.xml

 

https://experienceleague.adobe.com/en/docs/experience-manager-cloud-manager/content/getting-started/project-creation/build-environment#using-java-version

 

Just the cloudmanager/java-version file should work fine. I have tested this and it works fine.

September 26, 2025

Hey! I’ve faced a similar issue when working with Adobe Experience Manager (AEM) as a Cloud Service — especially when updating the Java version.

 Common Causes When Java Update Fails on AEM Cloud:

  1. Java 11 to 17 Upgrade?

    • AEM as a Cloud Service recently moved to Java 17 as default.

    • If your codebase has legacy constructs (reflection, illegal access, deprecated APIs), builds may succeed locally but fail during Cloud Manager pipeline execution.

  2. Check Compatibility in pom.xml:

    • Ensure you’re setting the correct compiler plugin:

       
       
<maven-compiler-plugin> <configuration> <source>17</source> <target>17</target> </configuration> </maven-compiler-plugin>
  • Bundle Manifest Issues

    • A mismatch in the Java version used during the local build and the one expected in OSGi bundle manifest can break deployment silently.

    • Check the Import-Package and Export-Package headers for compatibility.

  • AEM Cloud SDK and Dispatcher Tools

    • Always update your local AEM SDK version to match what AEM Cloud uses (available via Adobe's Software Distribution).

    • Some features (like servlet filters or annotations) behave differently in Cloud than in local Quickstart.

I ran into this during a recent project while learning AEM deployment practices via the Java Full Stack Developer course at Visible Campus in Bangalore. They cover Java cloud environments like AEM, Spring Boot, and containerized deployments — a great resource if you’re planning a long-term career in enterprise Java.