top of page
Search
  • Writer's pictureJuan Ayala

AEM as a Cloud Service & Java 11 Pipelines

Updated: Nov 11, 2021

Recently I started a new AEM as a Cloud Service project. The first thing I did was generate a new repository using the Maven archetype. I assumed it would be using Java 11 from the get-go. I came to learn it did not! Here are 3 things you'll need to get your AEMaaCS project ready for Java 11.


Update the Project to Use Java 11


As soon as I started to write Java code IntelliJ began screaming at my var. I love the var keyword in Java. The type inference speeds things up a lot. We need to update the root POM file. Set the Java version to 11 on the maven-enforcer-plugin and maven-compiler-plugin plugins.


<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <executions>
        <execution>
            ...
            <configuration>
                <rules>
                    ...
                    <requireJavaVersion>
                        <message>Maven must be executed with a Java 11 JRE or higher.</message>
                        <version>11</version>
                    </requireJavaVersion>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>11</source>
        <target>11</target>
    </configuration>
</plugin>

Your IDE should pick up on the POM changes and switch the project to Java 11. That was easy! On to the next step.


Make Sure Maven Is Using Java 11


Once I was done making my changes I opened up a terminal and tried to run mvn clean install -P autoInstallSinglePlackage to get everything deployed. The enforcer I had configured denied me. I ran mvn --version and sure enough, Maven was using Java 8.


maven version

First, let's download the Java 11 SDK. Adobe is officially supporting Azul Zulu OpenJDK. You can get it directly from azul.com or from Adobe's Software Distribution.


Second, update JAVA_HOME. I switch between projects a lot and I still need Java 1.8. I use jEnv to make transitions seamless.


Setting up jEnv


If you are using (or want to use jEnv) just follow the install instructions. Once you have installed jEnv and a JDK run the following command to get the paths to the JDKs on your machine

/usr/libexec/java_home -V

Locate the path to the JDK you need and add it to the list of jEnv managed versions

jenv add /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/

Once jEnv knows about your JDK, you need to enable the Maven plugin

jenv enable-plugin maven

Now set your project's JDK version. In the root directory run

jenv local zulu64-11.0.10

This will generate a .java-version file. From that point on Maven will always use that JDK at or below your project's directory.


Configure Java 11 on Cloud Manager


I was finally ready to push my project to Cloud Manager and deploy it. Imagine my chagrin when the pipeline failed on me. The enforcer was enforcing Java 11 again!


I trolled the documentation a little more. Java 8 is the default. To tell the pipeline to use an alternate JDK you need a .cloudmanager/java-version file. Create this file and make sure it gets committed into GIT

echo 11 > .cloudmanager/java-version

With the new file, I finally had a successful run.


Conclusion

As of August 2021 Java 8 is still the default on Cloud Manager. Things are moving along and I'm sure this will change soon. Take these extra steps to ensure you are using the latest on the cloud and on your local instance.

1,344 views0 comments

Recent Posts

See All
Post: Blog2_Post
bottom of page