Maven Git Project Setup

Git and Maven

Git Ignore

It’s useful to have some files and folders ignored by Git because you don’t want to put them under version control, or you don’t need to share them with others. Here’s a good list that should fit most needs based on the Adobe recommendations and expanded to include some extra entries.

# Ignore VLT folder and files
.vlt
.vlt-sync.log
.vlt-sync-config.properties

# Quickstart launches in the source tree
license.properties
crx-quickstart

# compilation results and jar files
# neither should be under SCM
target
*.jar

# IDE and OS artefacts
# You should have these in your global settings anyway
.idea
.classpath
.metadata
.project
.settings
maven-eclipse.xml
*.iml
*.ipr
*.iws
.DS_Store

Maven Archetype

You can use a Maven archetype to create a new project, which will give a good starting point. It’s worth noting however, this is only good and not perfect, so be prepared to tailor it to refine the configuration. There’s some really tasty low-hanging fruit that can yield solid benefits, which we will cover.

mvn archetype:generate \
    -DarchetypeRepository=http://repo.adobe.com/nexus/content/groups/public/ \
    -DarchetypeGroupId=com.day.jcr.vault \
    -DarchetypeArtifactId=multimodule-content-package-archetype \
    -DarchetypeVersion=1.0.2 \
    -DgroupId=com.example \
    -DartifactId=aemproject \
    -Dversion=1.0-SNAPSHOT \
    -Dpackage=com.example.aemproject \
    -DappsFolderName=aemproject \
    -DartifactName="Example AEM Project" \
    -DcqVersion="6.2.0" \
    -DpackageGroup="aemproject"

In summary what this does is:

  • connect to Adobe to use their Archetypes

  • select the multi-module archetype version 1.0.2

  • set groupId and artifactId for the new project

  • set a version number for the new project

  • define the java package to create for the project

  • add a description for the project as ‘artifactName’

  • use a specific version of AEM; this configures the dependencies in the project pom.xml

  • set the package group for the CRX package this project will create

With all these options, the generation is automatic, it just prompts yes/no to confirm the values. The project is created in a folder matching the artifactId value.

You can now proceed to build the project using Maven, but it’s better to reconfigure it first. Besides, it won’t do anything useful yet so there’s no rush.

Useful changes to the pom.xml

The pom.xml that is generated by the multi-module archetype has a few deficiencies that should be addressed from the start of the project.

Firstly, it includes declarations of the repositories used by Adobe. These should be removed in favour of using a global settings file in  /.m2/settings.xml that contains either these Adobe repositories or is set up to use Nexus as a proxy. I prefer the latter as it caches all the artifacts, making the builds more robust and not subject to service outages (Internet access or the Adobe server).