-
Notifications
You must be signed in to change notification settings - Fork 0
Description
The pom.xml file currently has the version hardcoded as 2.0.0. This can lead to issues with maintaining and updating the version across different branches and releases. It would be more efficient to dynamically retrieve the version from the git tags.
Proposed Solution
- Modify the pom.xml configuration to use a plugin that can fetch the version from git tags.
- This change will ensure that the version is always in sync with the current git tag, reducing the risk of discrepancies.
Implementation Example
To dynamically retrieve the version from git tags in the pom.xml of the NCEAS/osti-elink repository, follow these steps:
- Add the Maven Git Versioning Plugin: Modify the
pom.xmlfile to include the Maven Git Versioning Plugin. - Configure the Plugin: Update the
pom.xmlfile to use the plugin for versioning.
Here’s how you can modify the pom.xml file:
Step 1: Add the Plugin
Insert the following configuration into the <build> section of your pom.xml file:
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.0.0</version>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<gitPropertiesFile>${project.build.outputDirectory}/git.properties</gitPropertiesFile>
</configuration>
</plugin>Step 2: Update the Version Property
Replace the hardcoded version with a property that pulls from the git commit ID:
<properties>
<revision>${git.commit.id.describe}</revision>
</properties>
<version>${revision}</version>Example Updated pom.xml
Here’s how the relevant sections of your pom.xml will look after making these changes:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.ucsb.nceas</groupId>
<artifactId>osti-elink</artifactId>
<properties>
<revision>${git.commit.id.describe}</revision>
</properties>
<version>${revision}</version>
<build>
<plugins>
<!-- Other plugins -->
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.0.0</version>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<gitPropertiesFile>${project.build.outputDirectory}/git.properties</gitPropertiesFile>
</configuration>
</plugin>
</plugins>
</build>
</project>Benefits
- Easier version management.
- Reduces the chances of human error when updating the version.
References
Now, the pom.xml will dynamically retrieve the version from the git tags, ensuring it is always in sync with the current git tag.