Common Maven parent POM

se.jonand.maven:mvn-common:<version>

This is a parent POM that defines common properties for any Maven project, also for non Java projects. It makes release management with Maven with source control management for SVN simple for projects that inherit from it.

Execute of mvn deploy has no effect for projects that inherit directly from this POM as install of the artifact to the local Maven repository and deploy of it to a Maven repository only makes sense for artifacts that are meant to be used as dependencies for other Maven projects.

Execute of mvn release:prepare && mvn release:perform will work successfully when the POM that inherits from this POM has been configured as specified below. It cause the current version to be set to release (remove of SNAPSHOT from the version) and stored as a new tag in SVN and finally is the version set to SNAPSHOT for the next incremented version number.

To get access to this POM must the repository at maven.jonand.se be added to the list of repositories in the project’s POM file or as a repository in an active profile in the local Maven settings as described at the Maven page.

Properties

These are the properties defined and used of this POM and they may be redefined with custom values in projects that inherit from this POM.

  • maven.install.skip: Configures if the artifact should be installed to the local Maven repository on mvn:install. Defaults to false as this only makes sense to projects that may be used as Maven dependencies.
  • maven.install.skip: Configures if the artifact should be deployed to a Maven repository on mvn deploy. Defaults to false as this only makes sense to projects that may be used as Maven dependencies.
  • eclipse.projectName: The name of the eclipse project generated of mvn:eclipse:eclipse. Defaults to ${project.name} ${project.version}.
  • project.build.sourceEncoding: The encoding that the source should be read as when it is copied filtered to a packaged artifact. Defaults to UTF-8.
  • maven.compiler.source: The Java version for the source code. Defaults to 1.8.
  • maven.compiler.target: The Java version that the Java source should be compiled for. Defaults to 1.8.
  • mvn.local.repo.root: The root folder for the local Maven repositories. Defaults to C:/.m2
  • scm.url.root: URL to the root for SCM. Defaults to https://localhost/svn
  • scm.url.repo: The path in the SCM to the repository for this project where the first name in the path is the name of the repository and the remaining of the path is the path to the root folder in the repository for the project. Defaults to workspace/tools/maven/pom as the path for this POM.
    Important: Must not end with the artifactId name and trunk!
  • scm.url.trunk: The complete URL to the repository trunk in the SCM for this project. Defaults to ${scm.url.root}/${scm.url.repo}/${project.artifactId}/trunk
  • tagBase: The complete URL to the root folder for tags in the SCM for this project. Defaults to¬†${scm.url.root}/${scm.url.repo}/${project.artifactId}/tags

The property project.build.sourceEncoding only applies to resource filtering for packaged artifacts which usually are built from Java source. It is still configured for this POM as support for other Maven resource projects that may inherit from it but enable packaging. The most apparent example is Java archetypes that package but not compiles Java source.

The Maven compiler plugin version is not configured of this POM but the properties maven.compiler.source and maven.compiler.target are still included as support for projects that manage Java source and only inherit from this POM because they not need to compile the source. Again are archetypes the apparent example.

Usage

Projects that inherit from this POM need usually not to override any of the properties at all as long as they not also should be stored to a source control repository, SCM. See more about that below.

This POM specifies the version to be used for the maven-source-plugin, maven-javadoc-plugin, maven-install-plugin, maven-deploy-plugin and the maven-eclipse-plugin in its dependency management list as these plugins are added to the build by default of the Maven super POM. This POM also adds a specified version of the maven-release-plugin to the build list and org.apache.maven.wagon:wagon-ftp to the list of extensions.

This POM specifies that source and javadoc packages should be downloaded if available for dependencies. Install of the built artifact to the local Maven repository and deploy of it to the distribution repository is skipped as default.

Local repositories that may need to be created

This POM defines two local Maven repositories for its distribution management and that two local Maven repositories and one more local Maven repository are added to the list of repositories for Maven dependencies. Any project that inherit from this POM and specify dependencies or enable distribution management of the generated artifact must initially create these repositories as empty folders at the specified location.

  • mvn.repo.releases: ${mvn.local.repo.root}/releases
    Local distribution-repository for release versions.
  • mvn.repo.snapshots: ${mvn.local.repo.root}/snapshots
    Local distribution-repository for snapshot versions.
  • mvn.repo: ${mvn.local.repo.root}/repo
    Local repository aimed for manually installed third party dependencies.

These three local Maven repositories must also be defined as servers in the local Maven settings file.

Source control

This POM is customised for use of SVN for source control and projects that inherit from it should usually define their own value for the property scm.url.repo if they should be stored to a source control repository. Note that the value for this property must NOT end with the artifactId name and trunk. For example has mvn-common/trunk been left out from the value for this property for this POM.

As the macro that use the scm.url.repo property in the developerConnection tag gets expanded in the released version of a parent POM must each project that inherit from it specify the developerConnection tag exactly like this if the project should be stored to a source control repository.

To release a sub project with mvn release:prepare && mvn release:perform must also a working copy of the project have been checked out from the source control repository, its version should be set to SNAPSHOT, it should not depend to any other SNAPSHOT version and all changes to its files that are managed of source control must have been committed.

To import an initial version to SVN first create a folder structure for the projects path in the repository, for example at workspace/tools/maven/pom for the path tools/maven/pom in the repository workspace. Then create a project structure (branches, tags, trunk) at that path, for example a folder named mvn-common for this POM. Finally, to import the project files to source control, first execute mvn clean and delete any project files that not should be included in the import. Then execute import of the projects root folder, for example a folder named mvn-common for this POM, to the trunk, for example to the URL https://localhost/svn/workspace/tools/maven/pom/mvn-common/trunk.

Example

This is a complete example on use of this POM as the parent POM.

History

0.01 – 2014-09-01

The initial version of this POM which contained everything not mentioned in any of the next releases below.

0.02 – 2016-02-29

Updated all the plugins to the latest available version. Removed the maven-eclipse-plugin Maven-support for eclipse now is better provided of the Maven Integration for Eclipse plugin instead.