/buildmetadata-maven-plugin

The buildmetadata-maven-plugin captures and reports information about Maven builds.

Primary LanguageJavaApache License 2.0Apache-2.0

buildmetadata-maven-plugin

The build metadata maven plugin creates a detailed report of the various build time parameters employed during a build. The information includes useful data that can be used to provide better transparency and accountability of the build process. Meta data includes build times and dates, user environment information and Java/Maven command line options. The reporting is configurable and extensible as well as being adaptable for projects using multiple artifacts.

Maven Repository

You can access the binary artifact via Maven Central or the JBoss releases repository.

JBoss Releases:

http://repository.jboss.org/nexus/content/repositories/releases/com/redhat/rcm/maven/plugin/buildmetadata-maven-plugin/

Metadata Description

SCM information

  1. revision number
  2. revision date
  3. locally modified files
  4. URL of SCM server

System information

  1. build time
  2. operating system
  3. name
  4. architecture
  5. version

Java runtime

  1. vendor
  2. name
  3. version
  4. virtual machine
  5. compiler
  6. JAVA_OPTS

Maven execution information

  1. Maven version
  2. active profiles
  3. environment properties
  4. command line and executed goals

MAVEN_OPTS

  1. build user
  2. build host name
  3. Artifact and version group ID artifact ID build version
  4. project info
  5. home page URL
  6. categories
  7. tags

System Requirements

The following specifies the minimum requirements to run this Maven plugin:

  1. Maven 2.0
  2. JDK 1.5

Installation Instructions

Clone the repository to your workspace and build with maven:

  1. git clone https://github.com/release-engineering/buildmetadata-maven-plugin.git
  2. mvn install
  3. Edit your project pom.xml to include the following:

The options in the plugin's configuration section will produce a report that will include the command line executed along with the Maven and Java Options. For the full options available and details on how to extend functionality please refer to the upstream documentation linked below.

    <project>
      ...
      <!-- Set up the repository to fetch the buildmetadata-maven-plugin from -->
      <repositories>
        <repository>
          <id>repository.jboss.org</id>
          <name>JBoss Releases</name>
          <url>http://repository.jboss.org/nexus/content/repositories/releases/</url>
        </repository>
      </repositories>

      <pluginRepositories>
        <pluginRepository>
          <id>repository.jboss.org</id>
          <name>JBoss Releases</name>
          <url>http://repository.jboss.org/nexus/content/repositories/releases/</url>
        </pluginRepository>
      </pluginRepositories>

      <!-- Declare the dependancy on the buildmetadata-maven-plugin -->
      <dependencies>
        <dependency>
          <groupId>com.redhat.rcm.maven.plugin</groupId>
          <artifactId>buildmetadata-maven-plugin</artifactId>
          <version>1.3.1</version>
        </dependency>
      </dependencies>

      <!-- Configure the buildmetadata-maven-plugin with the required reporting options -->
      <build>
        <plugins>
          <plugin>
            <groupId>com.redhat.rcm.maven.plugin</groupId>
            <artifactId>buildmetadata-maven-plugin</artifactId>
            <version>1.3.1</version>
            <executions>
              <execution>
                <phase>initialize</phase>
                <goals>
                  <goal>provide-buildmetadata</goal>
                </goals>
                <configuration>
                  <createPropertiesReport>false</createPropertiesReport>
                  <xmlOutputFile>${project.build.outputDirectory}/META-INF/buildmetadata.xml</xmlOutputFile>
                  <hideCommandLineInfo>false</hideCommandLineInfo>
                  <hideMavenOptsInfo>false</hideMavenOptsInfo>
                  <hideJavaOptsInfo>false</hideJavaOptsInfo>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    ...
    </project>

Runtime Example

If you want to execute the plugin from the command line with no modifications to your pom file the following example can be used:

mvn clean install -X -C -B dependency:resolve-plugins \
-Dmaven.test.skip=true \
-Dbuildmetadata:provide-buildmetadata \
-Dbuildmetadata:createPropertiesReport=false \
-Dbuildmetadata:xmlOutputFile={project.build.outputDirectory}/META-INF/buildmetadata.xml \
-Dbuildmetadata:hideCommandLineInfo=false \
-Dbuildmetadata:hideMavenOptsInfo=false \
-Dbuildmetadata:hideJavaOptsInfo=false \
-Dbuildmetadata:addScminfo=true | tee build.log

Assuming the plugin configuration in your projects pom.xml matches the example provided then simply executing maven withthe install goal will create a buildmetadata.xml file in the generated jar file under the META-INF direcory of the archive.

mvn install

You can view the generated build.properties file in the archive without extracting it with the following command:

unzip -p example/MyApp/target/MyApp-1.0-SNAPSHOT.jar META-INF/buildmetadata.xml

The report will resemble the example below:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<buildmetadata xmlns="http://github.com/sbadakhc/buildmetadata-maven-plugin" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://github.com/sbadakhc/buildmetadata-maven-plugin http://github.com/sbadakhc/buildmetadata-maven-plugin">
<name>1.0-20131105-SNAPSHOT</name>
<version>1.0-SNAPSHOT</version>
<groupId>com.redhat.rcm</groupId>
<artifactId>HelloWorld</artifactId>
<date>2013-11-05T08:57:22</date>
<timestamp>1383638242882</timestamp>
<build-year>2013</build-year>
<project>
  <copyright-year>null-2013</copyright-year>
</project>
<scm>
  <revision>42c32d5c55a9fe7a0ec08ccf7719273fa268eadf</revision>
  <revision-date>2014-02-09T00:00:00</revision-date>
  <url>scm:git:git@github.com:sbadakhc/HelloWorld.git</url>
</scm>
<runtime>
  <build-server>localhost.localdomain</build-server>
  <build-user>sbadakhc</build-user>
  <os>
    <arch>amd64</arch>
    <name>Linux</name>
    <version>3.11.6-200.fc19.x86_64</version>
  </os>
 <java>
    <name>OpenJDK Runtime Environment</name>
    <version>1.7.0_45-mockbuild_2013_10_16_17_47-b00</version>
    <vendor>Oracle Corporation</vendor>
    <vm>OpenJDK 64-Bit Server VM</vm>
    <compiler>HotSpot 64-Bit Tiered Compilers</compiler>
 </java>
 <maven>
   <version>3.0.5</version>
   <commandline>-X -e install</commandline>
   <execution-project>com.redhat.rcm:HelloWorld:jar:1.0-SNAPSHOT</execution-project>
   <is-excution-root>true</is-excution-root>
   <goals>
     <goal>install</goal>
   </goals>
   <options>-Xmx4096m -XX:MaxPermSize=2048m -Xnoclassgc -XX:+DisableExplicitGC</options>
 </maven>
</runtime>
<misc>
  <metadata name="build.date.pattern">dd.MM.yyyy HH:mm:ss</metadata>
</misc>
</buildmetadata>

Goals

The following goals are supported. For a full explanation please refer to the upstream providers documentation.

  1. buildmetadata:build-point
  2. buildmetadata:buildmetadata-report
  3. buildmetadata:provide-buildmetadata

Notes

This project is a fork of http://www.smartics.eu/buildmetadata-maven-plugin

At the time of forking the project the buildmetadata-maven-plugin had not been deployed to Central. However since version 1.6.1 the upstream is now available in Central (See: https://github.com/smartics/buildmetadata-maven-plugin and https://repo1.maven.org/maven2/de/smartics/maven/plugin/buildmetadata-maven-plugin/ )