This project could be used to start developing project based on AEM.
To start developing application based on AEM it is recommended to use Gradle AEM Single instead.
Documentation for AEM plugin is available in project Gradle AEM Plugin.
Gradle AEM Plugin 6.x serie and upper will no longer support Groovy DSL and stands on Kotlin DSL coming with Gradle 5.0.
Documentation for:
- migrating Groovy DSL to Kotlin DSL (official Gradle docs).
- previous 5.x serie (navigates to branch
groovy
),
- Quickstart
- Environment
- Structure
- Features
- Building
- Tips & tricks
- Running tests
- Attaching debugger
- Extending build
-
Fork project using command:
git clone [email protected]:Cognifide/gradle-aem-multi.git && cd gradle-aem-multi && gradlew fork
and specify properties:
and wait until project is forked then enter configured target directory.
-
Setup user specific project configuration using command:
gradlew props
and specify properties:
-
Setup local AEM instances with dependencies and AEM dispatcher (see prerequisites) then build application using command:
aem/hosts gradlew setup
and wait till complete AEM environment will be ready to use.
-
Develop continuously application using command:
gradlew
or to just deploy AEM application (without running anything else):
gradlew :aem:assembly:full:packageDeploy
Tested on:
- Java 1.8
- Gradle 5.4.1
- Adobe AEM 6.5
- Docker 2.0.0.3
Project is divided into subpackages (designed with reinstallabilty on production environments in mind):
-
aem/assembly/full - non-reinstallable complete all-in-one package with application and contents (combination of subpackages: all). Useful to deploy all code by installing single package in a project stage when application is not live.
-
aem/assembly/app - reinstallable assembly package that contains only application code, not content (combination of subpackages: common, sites). Useful to deploy application code only in a project stage when application is live and content should remain untouched on production server.
-
aem/common - OSGi bundle with integrations of libraries needed by other bundles and global AEM extensions (dialogs, form controls etc). Only code unrelated to any site / AEM platform wide.
-
aem/sites - AEM sites module extension consisting of site specific code like: OSGi bundle with business logic, AEM components, templates, design.
-
aem/site.demo - consists of extra AEM pages that presents features of application (useful for testing). Helps application testers and developers in QA/UAT application feature tests.
-
aem/site.live - contains minimal set of pages needed initially to rollout new site(s) using installed application. Helps content authors to start working with application.
- Integrated Fork Plugin / project generator based on live archetypes.
- Interoperable Java and Kotlin code examples.
- Integrated popular UI build toolkit: NodeJS, Yarn and Webpack for advanced assets bundling (modular JS, ECMAScript6 transpilation, SCSS compilation with PostCSS, code style checks etc).
- Integrated SCSS compilation on AEM side using AEM Sass Compiler.
- Integrated popular AEM testing toolkit: wcm.io Testing.
- Example configuration for embedding OSGi bundles into CRX package (
embedPackage
). - Example configuration for installing dependant CRX packages on AEM before application deployment (
instanceSatisfy
).
Project is configured to have local environment which consists of:
- native AEM instances running on local file system,
- virtualized Apache HTTP Server with AEM Dispatcher module running on Docker (official httpd image).
Assumptions:
- AEM author available at http://localhost:4502
- AEM publish available at http://localhost:4503
- Apache web server with Virtual hosts configured for domains:
- http://example.com -> which maps to
/content/example/live
content root on publish - http://demo.example.com -> which maps to
/content/example/demo
content root on publish - http://author.example.com -> which is proxy to the author instance
- http://example.com -> which maps to
- Use command
gradlew
so that Gradle in version according to project will be downloaded automatically. - Deploy application:
- Full assembly and run all tests
gradlew
<=>:develop
- Only assembly packages:
gradlew :aem:assembly:full:packageDeploy
gradlew :aem:assembly:app:packageDeploy
- Only single package: [
gradlew :aem:sites:packageDeploy
,gradlew :aem:common:packageDeploy
,gradlew :aem:site.live:packageDeploy
,gradlew :aem:site.demo:packageDeploy
.
- Full assembly and run all tests
Build might look complicated, but to make a AEM development a breeze it just covers many things to be done within single task execution like setup
or develop
.
Graphical visualisation of task graph for resetup
task:
Task setup
will:
- set up AEM instances (author & publish)
- set up AEM environment (run HTTPD service on Docker) and install AEM dispatcher module
- build AEM application (compose assembly CRX package from many)
- migrate AEM application (for projects already deployed on production to upgrade JCR content in case of changed application behavior)
- clean AEM environment (restart HTTPD service then clean AEM dispatcher caches)
- check AEM environment (quickly check responsiveness of deployed application)
- run integration tests
- run functional tests
To sum up, all things needed by developer are fully automated in one place / Gradle build. Still all separate concerns like running tests, only building application, only running tests, could be used separately by running particular Gradle tasks.
- To run some task only for subproject, use project path as a prefix, for instance:
gradlew :aem:site.demo:sync
. - According to recommendations, Gradle daemon should be:
- enabled on development environments,
- disabled on continuous integration environments.
- To see more descriptive errors or want to skip some tasks, see command line documentation.
Certain unit tests may depend on the results of running gradle tasks. One such example is the testing of OSGi Services using OSGi Mocks where in order to run a test, the SCR metadata must be available for a class. Running a test like this in IntelliJ results in errors because the IDE is not aware of the Bundle plugin.
This can be worked around by configuring IntelliJ to delegate test execution to Gradle. In order to set this up, go to Settings > Build, Execution, Deployment > Gradle > Runner and set your IDE to delegate IDE build/run actions to Gradle. Alternatively, you can use a dropdown menu to use a specific runner or to decide on a test-by-test basis.
- Execute build with options
-Dorg.gradle.debug=true --no-daemon
, it will suspend, - Attach debugger on port 5005,
- Suspension will be released and build should stop at breakpoint.
For defining new tasks directly in build see:
The easiest way to implement custom plugins and use them in project is a technique related with buildSrc/ directory. For more details please read documentation.