Precompiled Bundled Scripts precompiled-bundled-scripts

AEM as a Cloud Service supports the deployment of the ui.apps component scripts as precompiled bundled scripts. This allows developers to precompile their scripts at build-time and package them as OSGi bundles.

Advantages of Deploying Precompiled Scripts via OSGi Bundles advantages

Deploying your scripts as precompiled bundled scripts has the following benefits:

  • Compiling scripts at build time allows developers to discover errors early in the development process.
  • Java API script dependencies are explicitly defined via the Import-Package and Export-Package bundle headers.
  • Inheritance (via sling:resourceSuperType) and delegation to other resource types (via HTL’s data-sly-resource block element or via the sling:include JSP tag, for example) can be mapped via the bundle’s meta-data.
  • Resource type versioning can be enforced in a similar way to the Java APIs.

Precompilation and Package Imports precompilation

The htl-maven-plugin can validate the syntax of HTL scripts, but it can also be used to transpile the HTL scripts into Java classes. These are then added to your Maven project’s generated-sources folder and picked-up by the maven-compiler-plugin.

The bnd-maven-plugin can be added to generate the OSGi bundle’s metadata for Java API imports.

Inheritance and Delegation inheritance-delegation

The OSGi framework provides a powerful way of defining requirements and capabilities to express contracts between various components. These are described via meta-data and enforced at runtime. Bundled scripts use this mechanism to express both their inheritance relationships (sling:resourceSuperType), as well as delegation (including other resource types in the rendering process).

The bnd plugin from the scriptingbundle-maven-plugin project can be used to extract the requirements and capabilities corresponding to the scripts provided by the ui.apps. content package

AEM Project Archetype Support support

Starting with version 31, the AEM Project Archetype can be used to correctly set up an AEM as a Cloud Service project to use precompiled bundled scripts.

In addition, the AEM Project Archetype configures the AEM as a Cloud Service SDK Build Analyzer Maven Plugin to validate the Java package-level as well as script-level dependencies.