gitmavenbuildnumber-maven-plugin

maven jar/war plugin to add git hash commit id


I wanted to add the Git commit id in the manifest.mf file for jar.

I have done the below configuration in pom xml plugin configuration,

I am able to get the git revision when i issue the maven goal clean buildnumber:create install

Is it possible to get the git revision without issuing buildnumber:create and through plugin configuration?

pom.xml

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>${maven.jarplugin.version}</version>
    <configuration>
        <archive>
            <manifest>    
                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                <addDefaultSpecificationEntries>false</addDefaultSpecificationEntries>
            </manifest>
            <manifestEntries>
                <Implementation-Build>${buildNumber}</Implementation-Build>
            </manifestEntries>
        </archive>
    </configuration>
</plugin>

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    <version>1.4</version>
    <executions>
        <execution>
            <phase>validate</phase>
            <goals>
                <goal>create</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <doCheck>true</doCheck>
        <doUpdate>true</doUpdate>
    </configuration>
</plugin>

Solution

  • Make sure the plugin is defined in the <plugins> section, not just <pluginManagement>.