Apache Commons logo

commons-parent

This page provides information about the commons-parent pom.xml
It has been updated for version 46 of the pom (but some discrepancies may remain). Please consult version 46 source in case of doubt.
Release Notes for version 46

Commons components use Maven as their primary build system and commons-parent is the parent pom for the components' Maven build.

Using a parent pom reduces the build configuration required for each individual component and standardizes the builds across Commons components.

Build

The following is a list of the main build features provided by commons-parent:

  • Reproducible Build - It is important that builds are consistently reproducible and in order to achieve this with Maven the same Plugin versions need to be used each time. commons-parent specifies the Plugin versions to be used in the <pluginManagement> section.
    • (N.B. the <reporting> section ignores anything specified in the <pluginManagement> section and component pom.xml's should specify the version of any additional report plugins they specify).
  • LICENSE and NOTICE files - automatically added to the jar files produced by the build to conform with the ASF License Policy.
  • MANIFEST.MF files - The following information is automatically included in the componentjar's manifest file:
    • Implementation-Title - set to the component's name
    • Implementation-Vendor - set to The Apache Software Foundation
    • Implementation-Vendor-Id - set to org.apache
    • Implementation-Version - set to the component version
    • Specification-Title - set to the component's name
    • Specification-Vendor - set to The Apache Software Foundation
    • Specification-Version - set to the component version
    • X-Compile-Source-JDK - set to the source option used by the compiler
    • X-Compile-Target-JDK - set to the target option used by the compiler
  • OSGi Enabled - OSGi metadata is automatically included in the component jar's manifest file enabling commons components to be used in an OSGi container. The following manifest entries are generated by default:
    • Bundle-Name - set to the component's name
    • Bundle-Vendor - set to The Apache Software Foundation
    • Bundle-Version - set to the component version
    • Bundle-ManifestVersion - set to 2
    • Bundle-License - set to http://www.apache.org/licenses/LICENSE-2.0.txt
    • Bundle-Description - set to the component's description
    • Bundle-SymbolicName - set to the component's package name (e.g. org.apache.commons.beanutils)
    • Bundle-DocURL - set to the component's website URL
    • Export-Package - set to the component's package names (can be overriden)
    • Import-Package - set to the package names of the component's dependencies
  • Java Version - source and target options can be configured through properties, and profiles are provided to test on different Java versions. Where necessary, plugin versions are down-graded to the latest version that runs on earlier JVMs. If later Java versions require updated plugins, this is done in a conditional profile (jdk7-plugin-fix-version).
  • Testing Coverage - both Jacoco and Cobertura are supported. These can be independently enabled.
  • Source Compatibility - both japicmp and clirr are supported. These can be independently enabled.

Release

The following is a list of the main release features provided by commons-parent through the release profile.

  • Binary and Source distributions
  • Signatures and Checksums
  • Javadoc and source jars

Additionally the RAT (release audit) report is automatically produced when generating a component's site. The RAT report checks the source files for appropriate License Headers.

Commons Release Plugin.

By default in the parent, the commons-release-plugin is disabled as to not stop folks' release practices. That said, for people interested in configuring the newly released (April 2018) release plugin, one needs to configure the following properties, for single module builds:

<properties>
    <commons.release.isDistModule>true</commons.release.isDistModule>
    <commons.distSvnStagingUrl>scm:svn:https://dist.apache.org/repos/dist/dev/commons/foo</commons.distSvnStagingUrl>
</properties>
where foo represents our component. Furthermore, during a release build, we ask that the svn folder be empty. We then generate our release build by runnning:
mvn -Duser.name=${my_apache_id} -Prelease -Ptest-deploy clean package site deploy
to test our deployment. Note, all of the staged items end up in target/commons-release-plugin/scm. And, to perform a full release, we run:
mvn -Duser.name=${my_apache_id} -Prelease clean package site deploy
Using the release plugin should build and stage the non-assembly built artifacts to Nexus, and stage the assemblies to the svn location along with the site and the RELEASE-NOTES.txt from the root of the project.

Site Generation

The following is a list of the main site features provided by commons-parent:

  • Standard Style and Navigation - commons-parent has a site.xml which is inherited by each component's site and provides standard Menu/Navigation and styling.
    • Menu/Navigation - The menu and breadcrumb options specified in the commons-parent's site.xml are included in the component's site.
    • Style - The commons-parent's site.xml specifies the commons-skin so that component's sites use a standard style and commons logo.
  • Common Information
    • Mailing Lists - Mailing list information is specified in commons-parent and Maven automatically generates a standard Mailing List page for each compoenent.
    • Organization Name - The Apache Software Foundation (inherited from the Apache Parent pom).
  • Standard Reports - The following reports are configured
    • RAT (release audit) Report - reports on the presence/absence of appropriate License Headers in source files.
    • Japicmp Report - reports are only generated when a jar file has been produced by the build, so mvn clean site will produce an empty japicmp report, whereas mvn clean package site will produce a full report. Furthermore, in building pom only modules, japicmp has a tendency to print out a stacktrace under the pretense of a warning because it does not understand how to properly skip such a module.
    • Surefire Report
    • Javadocs
    • Source Cross Reference
    • The pom excludes Maven defaults such as the license report which is against the ASF branding rules. The following are currently included by default (components can add extra ones if they wish, but cannot remove them).
      • index
      • summary
      • modules
      • project-team
      • scm
      • issue-tracking
      • mailing-list
      • dependency-info
      • dependency-management
      • dependencies
      • dependency-convergence
      • cim
      • distribution-management
  • Custom Issue Tracking Page - The commons-build-plugin provides a mechanism to generate a custom issue tracking page for commons components. See here for details of how to configure the component's pom and generate the page.
  • Download Page - The commons-build-plugin provides a mechanism to generate a download page for the latest release of a component. See here for details of how to configure the component's pom and generate the page.

Java Version

Configuring the Java Source/Target options

commons-parent configures the source and target options in the maven-compiler-plugin to use the ${maven.compiler.source} and ${maven.compiler.target} properties respectively.

So, for example, to configure a component to have source/target set to 1.4 add the following lines to the component's pom.xml:

          <properties>
              <maven.compiler.source>1.4</maven.compiler.source>
              <maven.compiler.target>1.4</maven.compiler.target>
          </properties>
        
NOTE: the Maven compiler plugin defaults to using the properties ${maven.compiler.source} and ${maven.compiler.target}; however the Commons Parent POM originally incorrectly used ".compile." rather than ".compiler." This was fixed in version 31 of the Commons Parent pom. See https://issues.apache.org/jira/browse/COMMONSSITE-69

MANIFEST.MF

In order to help check what source/target options were used when building a release, the property values used to configure the source/target options in the maven-compiler-plugin (i.e. ${maven.compiler.source} and ${maven.compiler.target}) are also written out to the component jar's MANIFEST.MF file with the following header names:

            X-Compile-Source-JDK:
            X-Compile-Target-JDK:
        

Testing with different Java versions

Using the target option ensures that the .class file format is compatible with the required Java version - but it does not prevent/catch the use of methods/classes which were introduced in later Java versions (this is because the build will use the current Java libraries by default). One way to ensure that components don't accidentally use classes/methods from a later version of Java is to compile and test using the actual target Java version.

However, it may be that one or more Maven plugins require a later version of Java than the component. For this reason commons-parent provides profiles for compiling/testing under different Java versions (correct as of version 36):

  • java-1.3 for compiling and testing using Java 1.3 (uses property JAVA_1_3_HOME)
  • java-1.4 for compiling and testing using Java 1.4 (uses property JAVA_1_4_HOME)
  • java-1.5 for compiling and testing using Java 1.5 (uses property JAVA_1_5_HOME)
  • java-1.6 for compiling and testing using Java 1.6 (uses property JAVA_1_6_HOME)
  • java-1.7 for compiling and testing using Java 1.7 (uses property JAVA_1_7_HOME)
  • java-1.8 for compiling and testing using Java 1.8 (uses property JAVA_1_8_HOME)
  • java-1.9 for compiling and testing using Java 1.9 (uses property JAVA_1_9_HOME)

In order for these profiles to work, you need to configure the relevant JAVA_1_N_HOME properties in your settings.xml file. [There is no need to configure properties for profiles you don't need.] Each property should be set to the directory where the relevant version of the JDK is installed. Note: the Maven compiler plugin has documentation on how this works.

Note: the maven-bundle-plugin outputs all property values which start with a capital letter as headers to the jar's MANIFEST.MF file. The commons-parent pom uses the <_removeheaders> instruction to suppress the specific JAVA_* properties used by the pom.

To ensure that the properties are only present if they are actually needed, you can define the property in the relevant profile in your settings.xml, for example:

        <settings>
            <profiles>
                <!-- Sample profiles showing different ways of defining the properties -->
                <profile>
                    <id>java-1.5</id>
                    <properties>
                        <!-- sample Windows definition -->
                        <JAVA_1_5_HOME>C:\jdk1.5.0_22</JAVA_1_5_HOME>
                    </properties>
                </profile>
                <profile>
                    <id>java-1.6</id>
                    <properties>
                        <!-- Sample Unix definition -->
                        <JAVA_1_6_HOME>/home/jenkins/tools/java/latest1.6</JAVA_1_6_HOME>
                    </properties>
                </profile>
                <profile>
                    <id>java-1.7</id>
                    <properties>
                        <!-- sample definition using an OS environment variable -->
                        <JAVA_1_7_HOME>${env.JAVA_1_7_HOME}</JAVA_1_7_HOME>
                    </properties>
                </profile>
                <!-- No need to define every possible java profile, only the ones you want to use (and have JDKs for) -->
            </profiles>
        </settings>
        

An alternative is to define the home directories as OS environment variables. For example:

          JAVA_1_8_HOME=$(/usr/libexec/java_home -v 1.8) # MacOS only
          JAVA_1_8_HOME=/path/to/java8/home # Other Unix OSes
          export JAVA_1_8_HOME
          

Once you have configured settings.xml or defined the OS variables you can, for example, compile and test with Java 1.6 using the following command:

            mvn clean test -Pjava-1.6
        

You can also provide the appropriate property definition on the command-line. (However for frequent use it is easier to update the settings file or ensure the OS defines the appropriate variables) This overrides any property setting in the settings.xml file, which in turn overrides the OS environment variable. For example:

            mvn clean test -Pjava-1.6 -DJAVA_1_6_HOME=/home/jenkins/tools/java/latest1.6
        

OSGi Information

OSGi Metadata

In order to use a Commons component (or any libaray) in an OSGi container (for example Apache Felix) then OSGi metadata needs to be included in the MANIFEST.MF file of the component's jar.

Generating the OSGi Metadata

commons-parent is configured to automatically add the OSGi metadata to the component jar's MANIFEST.MF using the maven-bundle-plugin when the package phase is executed: