April 27, 2020
Estimated Post Reading Time ~

Deploying bundles/packages to different environments through Maven

Create a folder cq-sample-all(projectname-all) under cq-sample(parent folder)
Create cq-sample-all/pom.xml and configure the environment-specific properties, module dependencies, and different profiles - refer the sample below

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLotrion="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>my-group-id</groupId> <!-- Change the groupid and artifactId of the paraent -->
<artifactId>cq-sample</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>cq-sample-all</artifactId> <!-- Change the artifcatId -->
<packaging>content-package</packaging>
<name>${project.groupId} - ${project.artifactId}</name>

<properties>
<cq.dev.author.server>aem-dev-author</cq.dev.author.server>
<cq.dev.author.host>localhost</cq.dev.author.host>
<cq.dev.author.port>4502</cq.dev.author.port>
<cq.dev.author.protocol>http</cq.dev.author.protocol>

<cq.dev.publisher1.server>aem-dev-publisher</cq.dev.publisher1.server>
<cq.dev.publisher1.host>localhost</cq.dev.publisher1.host>
<cq.dev.publisher1.port>4503</cq.dev.publisher1.port>
<cq.dev.publisher1.protocol>http</cq.dev.publisher1.protocol>

<!-- Add the other server details-->

</properties>

<!-- Add all the bundle/content modules as part of dependency. Change the artifactId of the modules-->

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>cq-sample-content</artifactId>
<version>${project.version}</version>
<type>content-package</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>cq-sample-bundle</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>maven-vault-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
<configuration>
<embeddedTarget>/apps/cq-sample/install</embeddedTarget> <!-- change the folder name(cq-sample) accordingly -->
<embeddeds>
<embedded>
<groupId>${project.groupId}</groupId>
<artifactId>cq-sample-bundle</artifactId>
<filter>true</filter>
</embedded>
<!-- Add additional bundle modules here as embedded -->
</embeddeds>
<subPackages>
<subPackage>
<groupId>${project.groupId}</groupId>
<artifactId>cq-sample-content</artifactId>
<filter>true</filter>
</subPackage>

<!-- Add additional content modules here as subPackage -->
</subPackages>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<!-- Profile for Development deployments -->
<!--Create the profile for different environments -->
<profile>
<id>Development</id>
<build>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<executions>
<execution>
<id>install-content-package-author</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
<configuration>
<failOnError>true</failOnError>
<useProxy>false</useProxy>
<packageFile>${project.build.directory}/${project.build.finalName}.zip</packageFile>
<targetURL>${cq.dev.author.protocol}://${cq.dev.author.host}:${cq.dev.author.port}/crx/packmgr/service.jsp</targetURL>
<serverId>${cq.dev.author.server}</serverId>
</configuration>
</execution>
<execution>
<id>install-content-package-publisher1</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
<configuration>
<failOnError>true</failOnError>
<useProxy>false</useProxy>
<packageFile>${project.build.directory}/${project.build.finalName}.zip</packageFile>
<targetURL>${cq.dev.publisher1.protocol}://${cq.dev.publisher1.host}:${cq.dev.publisher1.port}/crx/packmgr/service.jsp</targetURL>
<serverId>${cq.dev.publisher1.server}</serverId>
</configuration>
</execution>

<!-- Add execution for additional publisher with different id(increment the last digit)-->

</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

Add cq-sample-all(projectname-all) as part of modules in the parent pom as shown below(make sure cq-sample-all module is at the bottom)

<modules>
<module>bundle</module>
<module>content</module>
<module>cq-sample-all</module>
</modules>

Add the vault plugin in the parent pom.xml(e.g. cq-sample/pom.xml)

<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>maven-vault-plugin</artifactId>
<version>0.0.10</version>
<configuration>
<verbose>true</verbose>
</configuration>
</plugin>

In each bundle modules(e.g. cq-sample/bundle) pom.xml add the following configuration

<properties>
<skip.install>false</skip.install>
</properties>

<profiles>
<profile>
<id>buildOnly</id>
<properties>
<skip.install>true</skip.install>
</properties>
</profile>
</profiles>

Modify the maven-sling-plugin in individual bundle modules pom.xml:
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>maven-sling-plugin</artifactId>
<executions>
<execution>
<id>install-bundle</id>
<goals>
<goal>install</goal>
</goals>
<configuration>
<slingUrl>${cq.protocol}://${cq.host}:${cq.port}/system/console/bundles
</slingUrl>
<user>${cq.user}</user>
<password>${cq.password}</password>
<refreshPackages>true</refreshPackages>
<failOnError>true</failOnError>
<skip>${skip.install}</skip>
</configuration>
</execution>
</executions>
</plugin>

Configuration changes in content modules(e.g. cq-sample/content) pom.xml:
<properties>
<skip.goal>install</skip.goal>
</properties>

Add as part of the profiles
<profile>
<id>buildOnly</id>
<properties>
<skip.goal>build</skip.goal>
</properties>
</profile>

Remove the profiles autoInstallPackage and autoInstallPackagePublish from content modules(e.g cq-sample/content/pom.xml - the deployment to the publisher is taken care from cq-sample-all/pom.xml)

Configure the content-package-maven-plugin:
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<configuration>
<name>cq-sample-content</name>
<useProxy>false</useProxy>
<failOnError>true</failOnError>
<packageFile>${project.build.directory}/${project.build.finalName}.zip</packageFile>
<targetURL>${cq.protocol}://${cq.host}:${cq.port}/crx/packmgr/service.jsp</targetURL>
<userId>${cq.user}</userId>
<password>${cq.password}</password>
</configuration>
<executions>
<execution>
<goals>
<goal>${skip.goal}</goal>
</goals>
</execution>
</executions>
</plugin>

Add the below server configuration with the admin username and password to Maven settings.xml(repeat the same for all the configured servers in cq-sample-all/pom.xml)

<server>
<id>aem-dev-author</id>
<username>admin</username>
<password>admin</password>
</server>

Run the build by providing the following command (parent pom.xml)
mvn clean package install -PbuildOnly, Development

Development is the profile name configured in cq-sample-all/pom.xml.

To deploy the individual modules to author or publisher Replace the default server properties from the parent pom.xml

<crx.host>localhost</crx.host>
<crx.port>4502</crx.port>
<crx.username>admin</crx.username>
<crx.password>admin</crx.password>
<publish.crx.host>localhost</publish.crx.host>
<publish.crx.port>4503</publish.crx.port>
<publish.crx.username>admin</publish.crx.username> <publish.crx.password>admin</publish.crx.password>

with

<cq.protocol>http</cq.protocol>
<cq.host>localhost</cq.host>
<cq.port>4502</cq.port>
<cq.username>admin</cq.username>
<cq.password>admin</cq.password>

Change the server details in the properties in the parent pom.xml with author or publisher- cq-sample/pom.xml and run the individual module pom.xml(mvn clean install) to deploy the individual modules. 


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.