Reputation: 304
Short version: I want to store the latest revision-number (related to the individual module) from both current module AND its dependencies in the manifest of a jar.
I have a multi-module Maven project. The modules are built into shaded jars (which include all the dependencies) so that they are independently deployable. Some of the modules are dependent on other modules (a couple of the modules that are build first is "commons" for the other modules). When building these modules, I want to include the latest commit-revision of the module AND the dependencies latest commit-revision. My modules are all kept in the same git-repo (with no "sub-gits").
Example:
<module>common</module>
<module>data</module>
<module>application1</module>
The first two modules are common modules that are dependencies in application1
.
Lets say the latest commit was 864ccc where I made changes in both Data and application1
. Common
however was last changed in commit 889a01.
When building these modules, I expect the following output in the manifest:
Revision-App: 864ccc
Revision-Common: 889a01
Revision-Data: 864ccc
I have previously used buildnumber-maven-plugin by MojoHaus with SVN. With this setup i was able to accomplish this with the following in pom.xml:
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<URL>${project.url}</URL>
<Application-Build-Time>${timeStamp}</Application-Build-Time>
<Revision-Appl>${app.rev}</Revision-Application>
<Revision-Data>${data.rev}</Revision-Data>
<Revision-Common>${common.rev}</Revision-Common>
</manifestEntries>
</archive>
<outputDirectory>../target</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>${buildnumber-maven-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<version>1.8.5</version>
</dependency>
</dependencies>
<configuration>
<providerImplementations>
<svn>javasvn</svn>
</providerImplementations>
</configuration>
<executions>
<execution>
<id>timeStamp</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<buildNumberPropertyName>timeStamp</buildNumberPropertyName>
<format>{0,date,yyyy-MM-dd HH:mm:ss}</format>
<items>
<item>timestamp</item>
</items>
<revisionOnScmFailure>SVN_FAILURE</revisionOnScmFailure>
</configuration>
</execution>
<execution>
<id>appRev</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<buildNumberPropertyName>app.rev</buildNumberPropertyName>
<useLastCommittedRevision>true</useLastCommittedRevision>
<scmDirectory>${project.basedir}</scmDirectory>
</configuration>
</execution>
<execution>
<id>commonRev</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<buildNumberPropertyName>common.rev</buildNumberPropertyName>
<useLastCommittedRevision>true</useLastCommittedRevision>
<scmDirectory>${project.basedir}/../common</scmDirectory>
<getRevisionOnlyOnce>false</getRevisionOnlyOnce>
<revisionOnScmFailure>SVN_FAILURE</revisionOnScmFailure>
</configuration>
</execution>
<execution>
<id>dataRev</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<buildNumberPropertyName>data.rev</buildNumberPropertyName>
<useLastCommittedRevision>true</useLastCommittedRevision>
<scmDirectory>${project.basedir}/../data</scmDirectory>
<getRevisionOnlyOnce>false</getRevisionOnlyOnce>
<revisionOnScmFailure>SVN_FAILURE</revisionOnScmFailure>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<artifactSet>
<includes>
<include>com.company.package:*</include>
</includes>
</artifactSet>
<createDependencyReducedPom>true</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
But I can't for the life of me figure out how to do the same with git. I can only get the HEAD revision of the super-pom (containing the modules).
Could you help me get the same result with git?
Running mvn build gives me the following output:
[INFO] --- buildnumber-maven-plugin:1.4:create (appRev) @ common ---
[INFO] Executing: /bin/sh -c cd '/home/user/java/application1' && 'git' 'rev-parse' '--verify' 'HEAD'
[INFO] Working directory: /home/user/java/application1
[INFO] Storing buildNumber: 864cccf9056d273313eb9fb690b58674f72d4a6b at timestamp: 1539006765309
[INFO] Storing buildScmBranch: mvn-revision
[INFO]
[INFO] --- buildnumber-maven-plugin:1.4:create (commonRev) @ common ---
[INFO] Executing: /bin/sh -c cd '/home/user/java/common/../common' && 'git' 'rev-parse' '--verify' 'HEAD'
[INFO] Working directory: /home/user/java/common/../common
[INFO] Storing buildNumber: 864cccf9056d273313eb9fb690b58674f72d4a6b at timestamp: 1539006765326
[INFO] Storing buildScmBranch: mvn-revision
[INFO]
[INFO] --- buildnumber-maven-plugin:1.4:create (dataRev) @ common ---
[INFO] Executing: /bin/sh -c cd '/home/user/java/common/../data' && 'git' 'rev-parse' '--verify' 'HEAD'
[INFO] Working directory: /home/user/java/common/../data
[INFO] Storing buildNumber: 864cccf9056d273313eb9fb690b58674f72d4a6b at timestamp: 1539006765330
[INFO] Storing buildScmBranch: mvn-revision
[INFO]
And I get that running git rev-parse --verify HEAD
will give me that output. But I would like to have the output of the first row running git rev-list --verify HEAD -- .
in the the current workdir.
Do you have any ideas?
I don't need to stick with this plugin, I just want the result described.
Upvotes: 1
Views: 266