- Andrew Kos
- Bill Burlein
- Bryan Williams
- Celina Buczkowska
- Daniel Ryerson
- Jeff Brown
- John Kraus
- Joseph Mak
- Josh Durbin
- Mark Daugherty
- Matt Van Bergen
- Matthew Young
- Melissa Geoffrion
- Michael Kang
- Michael Chan
- Michael Hodgdon
- Mike Motherway
- Molly McDaniel
- Nadia Maciulis
- Pat McLoughlin
- Paul Michelotti
- Puru Hemnani
- Rohit Srinath
- Ryan Lunka
- Tom Kelly
A better way to manage Maven dependencies in Adobe CQ5
Sunday, January 27, 2013
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
<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
<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.
<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.
Interested in more specialized AEM/CQ know-how? Attend our CIRCUIT Conference this June in Chicago. For registration, our call for speakers, and all the other relevant details, head to www.circuit.citytechinc.com
A longtime enthusiast of logic and problem solving, it seems appropriate that Mark would be inspired by software ideas and technologies...
- More AEM/CQ5 SEO Best Practices: Redirects, Vanity URLs, and XML Sitemaps
- Get Ready for CIRCUIT This Summer - Our Developer Conference
- Resetting the Value of Select Boxes in Safari for iOS onChange
- The Importance of Regression Testing
- Integrating Adobe Experience Manager with Google Tag Manager
- Say Hello to the New Application Support Team
- Strategies For Fixing Misplaced AEM/CQ5 Edit Bars
- CVE-2013-4810: a(nother) Hack that Needn’t Happen
- Responsive Image Rundown
- Application Performance Management