April 26, 2020
Estimated Post Reading Time ~

How to include CQ package from other projects as a dependency in your project

We often come across a situation where we want to include package or jar files from other CQ project across the organization to your project.

Set Up: This assumes that you already have your project set up using Maven, Nexus. You need Nexus or any other repository management system to store artifact of jar or CQ package zip artifact you need to use in your project.

Assumption: You are using "content-package-maven-plugin" to create CQ package. More information about this artifact can be found here
http://dev.day.com/docs/en/cq/current/core/how_to/how_to_use_the_vlttool/vlt-mavenplugin.html

Solution:
For jar file it is simply adding it to your embed statement and for zip file you could use subPackages configuration. Once you will run maven install with this configuration, Other project package will also get installed with your package. Same works for uninstall of package as well. Geometrixx all package uses similar approach.

your final pom will look like this,

<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<!--Your other properties and build definition -->
<configuration>
<!-- All CQ package you want to install as part of your build -->
<subPackages>
<subPackage>
<groupId>YOUR SHARED GROUPID</groupId>
<artifactId>YOUR SHARED ARTIFACT</artifactId>
<filter>true</filter>
</subPackage>
</subPackages>
<!-- All third party OSGI bundle and jar you want to install as part of your build -->
<embeddeds>
<embedded>
<groupId>YOUR SHARED GROUPID</groupId>
<artifactId>YOUR SHARED ARTIFACT</artifactId>
<target>PATH WHERE YOU WANT THIS TO GO/target>
</embedded>
</embeddeds>
</configuration>
<executions>
<execution>
<goals>
<goal>package</goal>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>

</dependencies>
<!-- Your other dependencies -->
<dependency>
<groupId>YOUR SHARED GROUPID</groupId>
<artifactId>YOUR SHARED ARTIFACT</artifactId>
<version>JAR FILE VERSION/version>
<scope>provided</scope>
</dependency>
<!-- CQ PACKAGE FROM OTHER PROJECT DEPENDENCY -->
<dependency>
<groupId>YOUR SHARED GROUPID</groupId>
<artifactId>YOUR SHARED ARTIFACT</artifactId>
<version>STABLE VERSION OF CQ PACKAGE FROM DIFFERENT PROJECT</version>
<type>zip</type>
</dependency>
</dependencies>


NOTE: When you are using other CQ projects as dependency in to your project, make sure that other project is not overriding configurations in your project. You might have to adjust other project package filter accordingly.


By aem4beginner

No comments:

Post a Comment

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