Version 5

    For JBoss projects, all artifacts such as jars should contain information about the build in the MANIFEST.MF file.  For example svn revision, java version, and build date should all be included.  This makes it easier to find out how the jar was built and to rebuild it if necessary.

     

    Some of this information is automatically available to Maven through properties.  Other information can be retrieved using various plugins.

    For example, the buildnumber-maven-plugin can be used to gather information about the current SCM revision (buildNumber) and the time and date of the build (timestamp).  The buildnumber-maven-plugin can be configured like this.

     

          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.0-beta-3</version>
            <executions>
              <execution>
                <id>set-build-properties</id>
                <goals>
                  <goal>create</goal>
                </goals>
                <phase>validate</phase>
              </execution>
            </executions>
            <inherited>true</inherited>
            <configuration>
              <!-- If the plugin fails to get the scm revision, set it to "unavailable" -->
              <getRevisionOnlyOnce>true</getRevisionOnlyOnce>
              <revisionOnScmFailure>unavailable</revisionOnScmFailure>
              <timestampFormat>{0, date, long} {0, time, long}</timestampFormat>
            </configuration>
          </plugin> 
    
    

     

    To make the current version of maven available through a property (maven.version), the build-helper-maven-plugin can be used.

           <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
              <execution>
                <phase>validate</phase>
                <goals>
                  <goal>maven-version</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
    

     

    The following example shows how to configure the jar and assembly plugins so that this information is included in the generated artifacts.  This can be set in the parent POM's pluginManagement section and the settings will be inherited by all the child POMs.

     

          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-jar-plugin</artifactId>
              <version>2.2</version>
              <configuration>
                <archive>
                  <manifest>
                    <addDefaultSpecificationEntries>
                      true
                    </addDefaultSpecificationEntries>
                    <addDefaultImplementationEntries>
                      true
                    </addDefaultImplementationEntries>
                  </manifest>
                  <manifestEntries>
                    <Implementation-URL>${pom.url}</Implementation-URL>
                  </manifestEntries>
                  <manifestSections>
                    <manifestSection>
                      <name>Build-Information</name>
                      <manifestEntries>
                        <Maven-Version>${maven.version}</Maven-Version>
                        <Java-Version>${java.version}</Java-Version>
                        <Java-Vendor>${java.vendor}</Java-Vendor>
                        <Os-Name>${os.name}</Os-Name>
                        <Os-Arch>${os.arch}</Os-Arch>
                        <Os-Version>${os.version}</Os-Version>
                        <Scm-Revision>${buildNumber}</Scm-Revision>
                        <Scm-Url>${project.scm.developerConnection}</Scm-Url>
                        <Build-Time>${timestamp}</Build-Time>
                      </manifestEntries>
                    </manifestSection>
                  </manifestSections>
                </archive>
              </configuration>
            </plugin>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-assembly-plugin</artifactId>
              <version>2.2-beta-3</version>
              <configuration>
                <archive>
                  <manifest>
                    <addDefaultSpecificationEntries>
                      true
                    </addDefaultSpecificationEntries>
                    <addDefaultImplementationEntries>
                      true
                    </addDefaultImplementationEntries>
                  </manifest>
                  <manifestEntries>
                    <Implementation-URL>${pom.url}</Implementation-URL>
                  </manifestEntries>
                  <manifestSections>
                    <manifestSection>
                      <name>Build-Information</name>
                      <manifestEntries>
                        <Maven-Version>${maven.version}</Maven-Version>
                        <Java-Version>${java.version}</Java-Version>
                        <Java-Vendor>${java.vendor}</Java-Vendor>
                        <Os-Name>${os.name}</Os-Name>
                        <Os-Arch>${os.arch}</Os-Arch>
                        <Os-Version>${os.version}</Os-Version>
                        <Scm-Revision>${buildNumber}</Scm-Revision>
                        <Scm-Url>${project.scm.developerConnection}</Scm-Url>
                        <Build-Time>${timestamp}</Build-Time>
                      </manifestEntries>
                    </manifestSection>
                  </manifestSections>
                </archive>
              </configuration>
            </plugin>