This talk was presented at CQCON 2013 in Basel.
Learn how to master development workflows combining the power of CQ with Apache Maven and Git. Sometimes it can be hard to get up and running with other developers' Adobe CQ projects. Where is the code? How can you build it once you have it? How do you get it into CQ? What do you do with it once it's there? Anyone should be able to quickly and easily perform a git clone of a CQ project, followed by doing a Maven build and install, and then immediately be able to try it out and work on it within CQ. This session will show developers how they can structure their projects so that they are buildable "out of the box". We will provide hints and tips on how to structure your application in git, and explain which maven plugins to use in a range of circumstances.
See the CQCON website http://www.cqcon.eu/2013/en/speakers/andrew-savory.html or the online version of the presentation at http://www.andrewsavory.com/presentations/CQCon_2013_CQ_Maven_Methods/index.html
The source of the presentation is in github at https://github.com/savs/CQCon_2013_CQ_Maven_Methods
18. BUT WHAT ABOUT ...
reverting mistakes?
reproducible builds?
collaborating with others?
deploying to production?
19. WHY ISN'T IT EASIER TO BUILD A CQ SITE?
Laborious project inception
No two projects alike
Don't know project layout
Don't know project dependencies
Hard for others to reproduce
Hard to test
Lengthy RTFM or worse (no FM)
Documentation over convention
23. SO HOW DO WE FIX THIS?
Maven
Git
(or Subversion, or CVS ... ymmv)
Best Practices
24. MAVEN
“Maven is a software project management
and comprehension tool. Based on the
concept of a project object model (POM),
Maven can manage a project's build,
reporting and documentation from a central
piece of information.”
25. GIT
“Git is a free and open source distributed
version control system designed to handle
everything from small to very large projects
with speed and efficiency. ”
Version control is a system that records changes to a file or set of files over
time so that you can recall specific versions later.
26. BEST PRACTICES
“A best practice is a method or technique that
has consistently shown results superior to
those achieved with other means.”
In addition, a "best" practice can evolve to become better as improvements
are discovered.
27. WHAT DO WE WANT?
Minimal customisation
Standardised way to create a project
Standardised way to build a project
Standardised way to deploy a project
Standardised way to test a project
Standardised way to share a project
31. CONFIGURING MAVEN
Maven has a settings file that defines things like
repositories where plugins can be downloaded (typically
~/.m2/settings.xml).
We need to add a profile to point to the Adobe repository.
We then specify this repository when we use the
archetype plugin.
See also: Obtaining the Content Package Maven Plugin
33. CONFIGURING MAVEN
Enable the repository:
Or use the -P option to activate profile(s):
<activeProfiles>
<activeProfile>adobe-public</activeProfile>
</activeProfiles>
mvn -P adobe-public [...]
37. ARCHETYPES
archetype |ˈɑːkɪtʌɪp|
noun
a very typical example of a certain person or thing: he was
the archetype of the old-style football club chairman.
an original which has been imitated; a prototype: an
instrument which was the archetype of the early flute.
39. WHAT CQ ARCHETYPES ARE THERE?
simple-content-package
Generates a simple
multimodule-content-package
Includes the folder structure for developing a CQ
application (content package and bundle).
cqblueprints multi-module
Third-party archetype encapsulating best practices for
working with e.g. OSGi bundles, taglibs, and CQ content
See also:
content package
How to work with packages
40. ON PACKAGES
Packages enable the importing and exporting of repository
content. They are used to install new functionality, transfer
content between instances, or back up the repository
A package is a zip file in file system (vault) serialization
format
Packages include meta information - filter definitions,
import configuration, package properties
Packages are often managed through the CQ
Package Manager
41. ON BUNDLES
Bundles are modular containers of functionality for OSGi –
essentially a java module that contains application logic
Bundles consist of java classes and other resources needed
to deliver functionality or to provide services to other
bundles.
Bundles can be managed through the CQ
See also:
Web Console
Creating OSGi bundles using CRXDE
42. HOW TO USE AN ARCHETYPE
archetypeGroupId: identifies the archetype project
uniquely across all projects
archetypeArtifactId: the name of the archetype jar
without a version number
archetypeRepository: where to get the archetype from
(based on pluginRepository in settings.xml)
See also: and
mvn archetype:generate
-DarchetypeGroupId=foo
-DarchetypeArtifactId=bar
-DarchetypeVersion=1.0.0
-DarchetypeRepository=baz
Maven: Introduction to Archetypes Maven: Naming conventions
43. SIMPLE CONTENT PACKAGE ARCHETYPE
From the fine manual:
“Creates a maven project that is suitable for
installing resources for a simple CQ
application. The folder structure is that used
below the /apps folder of the CQ repository.
The POM defines commands for packaging
the resources that you place in the folders and
installing the packages on the CQ server.”
44. SIMPLE CONTENT PACKAGE USAGE
archetypeGroupId: com.day.jcr.vault
identifies the archetype project uniquely across all projects
archetypeArtifactId: simple-content-package-archetype
the name of the archetype jar without a version number
archetypeRepository: adobe-public-releases
where to get the archetype from (based on
pluginRepository in settings.xml)
mvn archetype:generate
-DarchetypeGroupId=com.day.jcr.vault
-DarchetypeArtifactId=simple-content-package-archetype
-DarchetypeVersion=1.0.1
-DarchetypeRepository=adobe-public-releases
46. SIMPLE CONTENT PACKAGE PARAMETERS
groupId: Like a package name, e.g.
com.yourcompany.myproject
artifactId: name of the jar without the version, e.g.
myproject
version: accept the default
package: not used in simple-content-package
appsFolderName: name of /apps/myproject, e.g. myproject
artifactName: Description in Package Manager
packageGroup: Group in Package Manager
See also: Maven: Naming conventions
47. SIMPLE CONTENT PACKAGE OUTPUT
Template directories
pom.xml file
Instructions for compiling, creating bundles, deploying
to CQ in packages
FileVault configuration files
53. WHY USE CQBLUEPRINTS MULTI-MODULE?
The cqblueprint multi-module archetype is developed by
“The things we wanted to consider with our
archetype is to address concerns of larger
teams”
headwire.com
54. CQBLUEPRINTS MULTIMODULE DESIGN
foo-view subproject: where css/html/js developers (frontend)
do their work
foo-taglib foo-services: where java developers (backend) do
their work
foo-config: where the configuration (runmode configs stored)
foo-content: how we get initial content and site structure onto
the developer's box quickly
foo-all: how we hand off builds to the next environment
60. GET IT IN GIT
git add *
git commit -m 'Initial project version'
61. GET IT IN GITHUB (OPTIONAL)
hub-new-repo is a shortcut for creating a repository on
github and pushing your local repo into it
See also:
See also:
cd project
git hub-new-repo
CLI remote github repo creation
github
70. HOW CAN WE BUILD SMARTER?
Create local zips and jars that you can upload:
mvn package
produces:
Content package output: target/yourapp-content-
1.0-SNAPSHOT.zip
Bundle output: target/testapp-bundle-1.0-
SNAPSHOT.jar
76. How do we develop in a world of maven builds and deploys
and git saves?
77. THE FILEVAULT TOOL
You can use the FileVault tool (vlt) to check in, check out,
update and sync local content with the repository.
Install: extract crx-
quickstart/opt/filevault/filevault.
[tgz|zip] and add to your path
Usage: vlt --credentials admin:admin co --
force http://localhost:4502/crx
See also: How to use the VLT Tool
78. SAMPLE DEVELOPMENT WORKFLOW
Use maven to build and deploy
Initialise vlt
Create components, templates with CRXDE Lite
Use vlt to copy back into local filesystem
Change locally
Use vlt to copy back into the repository
Add to git
86. MAVEN PROFILE FOR PRODUCTION
Add this to pom.xml:
Deploy using this profile:
Or one-time override: mvn -
Dcrx.host=another.host,crx.port=4504 -
PautoInstallPackage install
See also:
<profile>
<id>auto-deploy-prod</id>
<properties>
<crx.host>production.server.hostname</crx.host>
<crx.port>4502</crx.port>
</properties>
</profile>
mvn -PautoInstallPackage,auto-deploy-prod install
Introduction to build profiles
92. CREDITS
designed by from The Noun Project
designed by from The Noun Project
designed by from The Noun Project
designed by from The Noun Project
designed by from The Noun Project
designed by from The Noun Project
designed by from The Noun Project
designed by from The Noun Project
designed by from The Noun Project
designed by from The Noun Project
designed by from The Noun Project
Light Bulb Shane David Kenna
Question Anas Ramadan
Hard Disk Drive Eddie Alshehri
Time wayne25uk
Sync P.J. Onori
Sync Rohith M S
Cloud Upload Adam Whitcroft
Puzzle John O'Shea
Question Henry Ryder
Factory Adrijan Karavdic
Crash Test Dummy Luis Prado