Common Maven Java parent POM

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

This is a parent POM that defines common properties for a Java 8 Maven project. It inherits from mvn-common which makes release management with Maven with source control management for SVN simple for projects that inherit from it. But it also extends that POM to make it very easy and fast to create a high quality build setup for a Java project. On mvn deploy are these artifacts created for a project that inherits from this POM:

  • The JAR file artifact itself
  • A JAR file artifact for the source code
  • A JAR file artifact for the javadoc
  • A JAR file artifact for the test source code
  • A JAR file artifact for the test javadoc
  • Javadoc for the source in ${doc.root}/apidocs
  • Javadoc for the test source in ${doc.root}/test-apidocs
  • An EclEmma code coverage report in ${doc.root}/test-coverage

The generated javadoc header and footer contains the name of the artifact and copyright information that is easy to customise.

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. See also the properties defined for mvn-common which is inherited of this POM.

  • copyright.name: The name of the copyright owner for this project which will be included in ${javadoc.bottom} in the javadoc.
  • copyright.year.from: The year the project was created which will be included in ${copyright.year} in the javadoc.
  • copyright.year.to: The last year development was done for the project which will be included in ${copyright.year} in the javadoc.
  • javadoc.show: The lowest access modifier level for API elements to be included in the javadoc. Defaults to protected.
  • doc.root: The root folder for the project’s generated javadoc and test coverage report. Defaults to ${mvn.local.repo.root}/docs/${project.artifactId}/${project.version}.
  • copyright.year: The copyright year which will be included in ${javadoc.bottom} in the javadoc. Defaults to “${copyright.year.from}, ${copyright.year.to}”.
  • javadoc.header: The name and version of the artifact which will be included in the javadoc. Defaults to “<![CDATA[<b>${project.name}<br/>ver. ${project.version}</b>]]>”.
  • javadoc.bottom: The copyright statement which will be included in the javadoc. Defaults to “<![CDATA[<p style=”text-align: center;”><i>Copyright &copy; ${copyright.name} ${copyright.year}. All Rights Reserved.</i></p>]]>”.
  • javadoc.url.javase: The URL to the javadoc for the version of Java SE the project has been developed for. Defaults to “http://docs.oracle.com/javase/8/docs/api/”.
  • javadoc.url.slf4j: The URL to the javadoc for SLF4J which is a dependency to this POM. Defaults to “http://www.slf4j.org/apidocs/”.
  • javadoc.url.logback: The URL to the javadoc for Logback which is a dependency to this POM. Defaults to “http://logback.qos.ch/apidocs/”.
  • javadoc.url.junit: The URL to the javadoc for JUnit which is a dependency to this POM. Defaults to “http://junit.org/apidocs”.
  • javadoc.url.assertj: The URL to the javadoc for AssertJ which is a dependency to this POM. Defaults to “http://joel-costigliola.github.io/assertj/core/api/”.
  • javadoc.url.mockito: The URL to the javadoc for Mockito which is managed of the dependency management for this POM. Defaults to “http://docs.mockito.googlecode.com/hg/latest/index.html?org/mockito/”.
  • maven.install.skip: Configures if the artifact should be installed to the local Maven repository on mvn:install. Overrides the parent configuration and defaults to true.
  • maven.install.skip: Configures if the artifact should be deployed to a Maven repository on mvn deploy. Overrides the parent configuration and defaults to true.

Some other properties not configured of this POM but that may be useful to set sometimes are these properties.

  • maven.javadoc.skip: Skips generation of javadoc which not needs to be done every time and it saves some build time if it is turned off.
  • jacoco.skip: Skips generation of the test coverage report which may save some build time that may be useful temporarily sometimes.
  • maven.test.skip: Skips execution of test cases which may be useful to do temporarily sometimes if a change have caused a lot of tests to fail.
  • maven.test.skip.exec: Skips execution of test cases but still builds the test-jar, if test-jar is added as a goal for the maven-jar-plugin execution.

Usage

See also the usage for mvn-common for information about local repositories that must be created and configuration of source control management.

As long as projects that inherit from this POM not also should be stored to a source control repository, SCM, see more about that in the usage for mvn-common, is it usually only the properties that customise the javadoc as specified below that needs to be overridden.

Beside build configuration for generation of the artifacts specified above does this POM also specify dependency management for use of SLF4J and Logback and Junit, AssertJ and Mockito for test. It includes SLF4J, Logback, Junit and AssertJ in its dependency list.

The Maven compiler plugin is configured of the dependency management in this POM and as it inherits from mvn-common is it configured to copy filtered source as UTF-8, compile it as Java 8 source for a Java 8 runtime environment.

Skipped test execution, javadoc generation and test coverage report

As described above may test execution, generate of javadoc and generate of the test coverage report temporarily be skipped if these properties are added to the properties list or added as Java system properties on the command line.

 javadoc

The generated javadoc contains a copyright statement that needs to be configured with properties like this.

The properties above cause the generated copyright statement to read like this.

Copyright © My Company 2014, 2015. All Rights Reserved.

To customise the copyright statement to for example not contain the word copyright may the property javadoc.bottom be overridden. For example do I usually override it like this in my own code.

 Examle

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 – 2014-11-05

Added links to the javadoc for SLF4J, Logback, JUnit, AssertJ and Mockito.

0.03 – 2016-02-29

Updated all the plugins and the dependencies to the latest available version. Added Mockito to the dependency list to get it included as a default dependency in projects, it was only includend in the dependeny management list before.