In the root of my project is pom.xml and .git. My maven pom.xml looks like:
<profile>
<id>git</id>
<activation>
<file>
<exists>.git</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>7.0.0</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
<configuration>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
From the console output, I can see that it is run once this way, but child jars that attempt to set it in the manifest end up having: '${git.commit.id.abbrev}' verbatim.
While I could just run this each time for each project, I'd like to run it once.
Is that possible?
Using a profile is the wrong way. The plugin will handle all the cases required. Also setting
dotGitDirectoryis not necessary nor useful that is the default of the plugin. That violates the convention over configuration paradigm.First define the version and the basic configuration of the plugin via
pluginManagementlike this:some of the configurations parts might be changed if required
generateGitPropertiesFilemaybe?The part
runOnlyOnceis an important one within a multi module build which means the plugin itself will execute only once to read the Git information and only at the root level (where the.gitdirectory can be found). If you don't set that totrueit will try to read the Git information in each child which is not necessary (that works but it's a wast of time; only in case where you might use Git submodules/subtrees it might be required).The next important thing is to bind the plugin to the life cycle. That has to be done in the
pluginssection (NOT in pluginManagement) like this:The plugin itself binds by default to the
initializephase so it is not required to define the phase on your own.