A better way to manage Maven dependencies in Adobe CQ5

When starting a new CQ5 project, setting up a Maven POM with project dependencies can be an unnecessarily time-consuming task.  Dependencies specified in the POM file must match those provided by the CQ5 OSGi container to prevent deployment and runtime issues, and the process of manually extracting Maven metadata from OSGi bundles in the Felix console is tedious and error-prone.  We can do better, and fortunately, Adobe has provided the Maven Archiva Servlet to streamline this process.


The Archiva servlet is commonly used to allow a CQ5 instance to function as a Maven repository, but there is an additional, undocumented feature of the servlet that generates a POM file for all of the installed bundles in the OSGi container.  From the generated POM file, we can copy the dependencies as needed into our project POM without any additional work to verify artifact IDs, versions, etc.

After downloading and installing the Maven Archiva Servlet package, this URL can be used to generate the POM file:


...or using cURL: 

curl http://localhost:4502/maven/repository/com/day/cq5-parent/0.0.1-SNAPSHOT/cq5-parent.pom > pom.xml

The <dependencyManagement> section of the generated POM can then be merged into an existing project's parent POM as necessary.  With this section defined, specifying dependencies in child modules requires only the <groupId> and <artifactId> for each dependency.

In a typical multi-module CQ5 Maven project, defining a dependency management section is helpful for several reasons:

  • As your project code evolves, it's highly likely that you will be using additional CQ5 and Sling libraries.  Defining the set of all libraries provided by the container, regardless of whether they are immediately needed, reduces future effort.
  • The <dependencyManagement> section allows for the convenience of defining these available dependencies for possible later use without polluting the <dependencies> section of the POM with unused artifacts.
  • Complex projects may have several modules with overlapping dependencies.  Using a dependency management section, versions and scopes are defined in one place, which eliminates redundant specification in module POMs.

A well-defined Maven dependency strategy coupled with the Archiva Servlet tool greatly simplifies the bootstrapping process for new CQ5 projects.