Monday, July 28, 2014

How to include all CQ dependencies in CQ6

Use case: Prior to CQ6 you have to add dependencies for each class you are using in your pom.xml, Way to find dependencies was (Maven org http://mvnrepository.com or using adobe central http://repo.adobe.com/nexus/content/groups/public through dependency finder HOST:PORT/system/console/depfinder). With CQ6 now all dependencies are provided through one artifactID.

Prerequisite: Maven, CQ Project Set Up 

Solution: Include following line in your dependency management for your pom.xml (Depending upon project this could be at any location usually it is your Project parent pom)


<dependencyManagement>
<!-- All Your Third party dependency -->
<!-- AEM 6.0 -->

      <!-- All AEM Dependencies for JSP compilation -->

      <dependency>
        <groupId>com.adobe.aem</groupId>
        <artifactId>aem-api</artifactId>
        <version>6.0.0.1</version>
        <scope>provided</scope>
      </dependency>

      <!-- All AEM 6.1 Dependency added to end of file -->


      <dependency>
        <groupId>com.adobe.cq.social</groupId>
        <artifactId>cq-socialcommunities-api</artifactId>
        <version>1.7.197</version>
        <scope>provided</scope>
      </dependency>


      <dependency>
        <groupId>com.adobe.aem</groupId>
        <artifactId>uber-jar</artifactId>
        <version>6.1.0</version>
        <scope>provided</scope>
        <classifier>obfuscated-apis</classifier>
      </dependency>


</dependencyManagement>

Note that this version could change depending upon new releases of CQ, You can track them from http://repo.adobe.com/nexus/content/repositories/releases/com/adobe/aem/aem-api/

Some Trick: Note that above will include all AEM-API dependencies, other way to check what minimum dependency is needed is to create a multi module project using AEM plugin for eclipse more example http://docs.adobe.com/content/docs/en/dev-tools/aem-eclipse.html .

You can also upload uber-jar with apis classifiers instead of obfuscate-apis classifier to your Nexus or dependency management system. 

To upload this uber-jar to your nexus you can use something like,

mvn deploy:deploy-file -Durl=YOUR-REPO -Dfile=uber-jar-6.1.0-apis.jar -DartifactId=uber-jar -Dversion=6.1.0 -DgroupId=com.adobe.aem -Dclassifier=apis -Dpackaging=jar -DrepositoryId=YOUR-REPO-ID

Once you have uber-jar with apis classifier ready, You can use something like

      <dependency>
        <groupId>com.adobe.aem</groupId>
        <artifactId>uber-jar</artifactId>
        <version>6.1.0</version>
        <classifier>apis</classifier>
        <scope>provided</scope>
      </dependency>


I see that minimum these are needed when you use this,

As always let me know if you want me to add more details in this posting.

2 comments:

  1. Hi Yogesh,

    In minimum recommendation section:

    <dependency>
    <groupId>org.osgi</groupId>
    <artifactId>org.osgi.core</artifactId>
    </dependency>

    <dependency>
    <groupId>org.osgi</groupId>
    <artifactId>org.osgi.compendium</artifactId>
    </dependency>

    why is this used, instead of:

    <dependency>
    <groupId>org.apache.felix</groupId>
    <artifactId>org.osgi.core</artifactId>
    <version>1.4.0</version>
    <scope>provided</scope>
    </dependency>
    <dependency>
    <groupId>org.apache.felix</groupId>
    <artifactId>org.osgi.compendium</artifactId>
    <version>1.4.0</version>
    <scope>provided</scope>
    </dependency>

    I always assumed felix was the better solution but now I'm not sure.

    What are the benefits/loses of using the recommended group?

    ReplyDelete
    Replies
    1. Hello Mathew,
      Thanks for recommendation. Changed my posting. Felix should be right one in this case.
      Yogesh

      Delete