Saturday 3 July 2021

How to update JDK version of Cloud Manager within your program as part of the build

 AEM AS CLOUD SERVICE VIDEO TUTORIAL SERIES

What are the available JDK versions with cloud manager?

Java versions installed are Oracle JDK 8u202 and 11.0.2.

Some times, when we deploy our code, people complaint java version is not matching (for e.g. we are using a JDK 11 specific API and this Java class is giving error in cloud manager) We will see how to set the relevant java version now.

How to update the Java version of project build environment in AEM As Cloud Manager

By default, projects are built using Java 8. Customers who want to use Java 11 in their projects can do this using the Apache Maven Toolchains Plugin.

In the pom.xml file, add a <plugin> entry that looks like this:

<!-- START -->
        <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>11</version>
                        <vendor>oracle</vendor>
                    </jdk>
                </toolchains>
            </configuration>
        </plugin>
<!-- END -->


A few FAQs about AEM As Cloud Service build environment are given below

What is the OS used for AEM as CLoud service?

Build environment is Linux-based, derived from Ubuntu 18.04.

At present what is the maven version?

The installed maven is - Apache Maven 3.6.0 version.

Which java versions are supported by AEM as cloud service?
Java versions installed are Oracle JDK 8u202 and 11.0.2.

Which repository is configured as part of Maven Build ?
adobe-public

Any other tools or packages available in AEM As Cloud environment?
unzip, bzip2, libpng, imagemagick, graphicsmagick

My code has some script with Python or ruby script and I need to trigger it as part of my code build. Is this possible?

For this we need an appropriate language interpreter installed. This can be done by calling the 'exec-maven-plugin' to invoke APT. See an example below,

<!-- START -->
        <profile>
            <id>install-Ruby</id>
            <activation>
                <property>
                        <name>env.CM_BUILD</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.6.0</version>
                        <executions>
                            <execution>
                                <id>apt-get-update</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>apt-get</executable>
                                    <arguments>
                                        <argument>update</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>install-ruby</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>apt-get</executable>
                                    <arguments>
                                        <argument>install</argument>
                                        <argument>-y</argument>
                                        <argument>--no-install-recommends</argument>
                                        <argument>ruby</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
<!-- END -->