How to switch your AEM Maven Project to Java 11

You are using an AEM Project that was built by the wcm.io Maven Archetype for AEM or inherits the build settings from wcm.io AEM Global Parent.

Your project is currently configured for Java 8 and you want to switch to Java 11 (which is supported and recommended since AEM 6.5).

Switch Maven Project to Java 11

  1. Make sure to update to the latest version of aem-global-parent (at least version 1.2.34, which includes global-parent 26).
  2. Update properties in your parent pom to define the Java version to build against:
    • Remove:

          <!-- compiler settings -->
          <build.compiler.source>1.8</build.compiler.source>
          <build.compiler.target>1.8</build.compiler.target>
    • Add instead:

          <!-- Java version -->
          <java.version>11</java.version>
  3. If you are using annotations like javax.annotation.PostConstruct in your Sling Model classes you need to add this dependency to your OSGi bundle POMs (it's version is defined in the wcm.io AEM Dependencies POM since version 6.5.0):

    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-annotation_1.3_spec</artifactId>
      <scope>provided<scope>
    </dependency>
  4. If you are using Eclipse to develop your project make sure the Eclipse IDE itself is running with Java 11 as well. You may add the path <Java 11 Path>/bin to your system path (before any other Java paths) to achieve this.

Compile with Java 11 against Java 8

If you want to compile with Java 11 but produce artifacts compatible with Java 8, do the same steps as described above, but add a different properties block:

    <!-- Java version -->
    <java.version>1.8</java.version>
    <build.compiler.release>8</build.compiler.release>