AEM Multi Module Project : Comprehensive Guide
Setting up AEM Multi Module Project is the very first step in any project development. This has become very easy using latest maven archetypes, but many developers are still confused on how different modules created using archetypes interact with each other and what kind of data should be associated with which module. In this tutorial we will understand below topics:-
- Overview of different Modules created using Archetype and best practices.
- Create AEM Multi Module Project Using Latest Archetype.
Overview of Maven Modules created using Archetype and recommended best practices
The AEM Project Archetype is a Maven template that creates a minimal, best-practices-based Adobe Experience Manager (AEM) project as a starting point for your project.
Of course for successful AEM project there are many items, but using the AEM Project Archetype provides a sound foundation and is strongly recommended for any AEM project.
Note:- The latest AEM Project Archetype can be found on GitHub.
AEM Archetype is build of below Modules:-
It contains all of the rendering code needed for the site beneath
/apps i.e. JS and CSS clientlibs which will be stored in an AEM format called clientlibs, components, and templates.
The Apache Jackrabbit FileVault Package plugin is used to compile the contents of the ui.apps module into an AEM package that can be deployed to AEM. The global configurations for the plugin are defined in the parent pom.xml.
Parent pom.xml includes a configuration for the
filterSource for the Jackrabbit FileVault Package Plugin. The
filterSource points to the location of the
filter.xml file that is used to define the jcr paths that are included in the package. In addition to the Jackrabbit FileVault Package Plugin is a definition of the Content Package Plugin which is used to then push the package into AEM.
The ui.apps pom (
<src>/<project>/ui.apps/pom.xml) provides the
embedded tags for the
embedded tags include the compiled core bundle as part of the ui.apps package and where it will be installed.
It includes all java code needed for the implementation like OSGi services, listeners, and schedulers, servlets and request filters.
The Maven Bundle Plugin defined in the
core pom.xml is responsible for compiling the Java code into an OSGi bundle that can be recognized by AEM’s OSGi container.
Note that this is where the location of Sling Models are defined.
These are Java-based integration tests.
It contains includes baseline content and configurations beneath /content and /conf. The major difference is that the nodes stored in ui.content can be modified on the AEM instance directly. In content filter.xml
mode="merge" attribute is added to the path to ensures that the configurations deployed with a code deployment do not automatically override content or configurations that have been authored on the AEM instance directly.
ui.content/pom.xml includes an extra configuration property called acHandling, set to merge_preserve under FileVault Package Plugin because the ui.content module includes Access Control Lists (ACLs).In order for these ACLs to be imported into AEM the acHandling property is needed
Best practice:- In many cases, especially at the beginning of an AEM project it is valuable to persist configurations, like templates and related content policies, to source control. This ensures that all developers are working against the same set of content and configurations and can ensure additional consistency between environments. Once a project reaches a certain level of maturity, the practice of managing templates can be turned over to a special group of power users. Source
It contains runmode-specific OSGi configs for the project.
ui.frontend.none: (optional) skip creating frontend module with any webpack artifact.
ui.frontend.general: (default) contains the artifacts required to use the general Webpack-based front-end build module.
ui.frontend.react: (optional) contains the artifacts required when using the archetype to create a SPA projects based on React.
ui.frontend.angular: (optional) contains the artifacts required when using the archetype to create a SPA projects based on Angular.
It contains Selenium-based UI tests.
This is a single content package that embeds all of the compiled modules (bundles and content packages) including any vendor dependencies.
It runs analysis on the project, which provides additional validation for deploying into AEM as a Cloud Service.
The aemanalyser-maven-plugin available in all module is used to run checks on all dependencies added to the project as defined in Cloud Manager deployment pipeline.
If you add additional dependency to the pom.xml, analyser plugin will try to compile and test this jar at run time. If it doesn’t find this jar included at run time then this validation process will fail. You either need to embed this dependency into your own bundle, or you find an OSGI-version of that bundle and deploy it along with your core bundle.
<plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>4.2.1</version> <extensions>true</extensions> <configuration> <instructions> <Embed-Dependency>jackson-dataformat-csv</Embed-Dependency> <Embed-Transitive>true</Embed-Transitive> <Import-Package> com.fasterxml.jackson.* </Import-Package> </instructions> </configuration> </plugin> Under Dependencies:- <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-csv</artifactId> </dependency>
More about the plugin : https://github.com/adobe/aemanalyser-maven-plugin/blob/main/aemanalyser-maven-plugin/README.md
Create AEM Multi Module Project Using Latest Archetype
There are couple of ways for creating a project like using Eclipse IDE, command line etc. I personally prefer command line and use the same in this tutorial for creating the project.
Open your command line or terminal and adjust below command as per your use:-
Lets consider, i need to create a new project using archetype 35 , my project name is AEM CQ5 Tutorials, i want my java files under com.aemcq5tutorials, i need general frontend module, my current aem version is 6.5.10.
mvn -B archetype:generate \ -D archetypeGroupId=com.adobe.aem \ -D archetypeArtifactId=aem-project-archetype \ -D archetypeVersion=35 \ -D aemVersion="6.5.10" \ -D appTitle="AEM CQ5 Tutorials" \ -D appId="aemcq5tutorials" \ -D groupId="com.aemcq5tutorials" \ -D frontendModule="general"
That’s it run the above command and it will create a project for you. Couple of important points to note:-
- Set aemVersion=cloud for AEM as a Cloud Service;
Set aemVersion=6.5.0 for Adobe Managed Services, or on-premise.
The Core Components dependency is only added for non cloud aem versions as the Core Components are provided OOTB for AEM as a Cloud Service.
- Adjust appTitle=”AEM CQ5 Tutorials” to define the website title and components groups.
- Adjust appId=”aemcq5tutorials” to define the Maven artifactId, the component, config and content folder names, as well as client library names.
- Adjust groupId=”com.aemcq5tutorials” to define the Maven groupId and the Java Source Package.
- AEM Archetype sources https://github.com/adobe/aem-project-archetype
- Using AEM Archetype https://docs.adobe.com/content/help/en/experience-manager-core-components/using/developing/archetype/overview.html
Leave a Reply