Empty git.properties is generated in submodules when injectAllReactorProjects=true starting from 8.0.0
KTannenberg opened this issue ยท 7 comments
Describe the bug (required)
When running git-commit-id-plugin
on a multi-module maven project with a parent pom and injectAllReactorProjects
set to true
, all generated git.properties
in submodules will end up with no content.
This bug affects versions 8.0.0+ of plugin, version 7.0.0 is the latest not affected one.
Tell us about your plugin configuration (required)
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>${git-commit-id-maven-plugin.version}</version>
<configuration>
<prefix>git</prefix>
<dateFormat>yyyy-MM-dd'T'HH:mm:ssXXX</dateFormat>
<dateFormatTimeZone>UTC</dateFormatTimeZone>
<dotGitDirectory>${maven.multiModuleProjectDirectory}/.git</dotGitDirectory>
<gitDescribe>
<skip>false</skip>
<always>true</always>
</gitDescribe>
<injectAllReactorProjects>true</injectAllReactorProjects>
<skipPoms>false</skipPoms>
<!-- Clear defaults from spring-boot-starter-parent -->
<verbose>true</verbose>
<generateGitPropertiesFile>false</generateGitPropertiesFile>
<generateGitPropertiesFilename>NONE</generateGitPropertiesFilename>
</configuration>
<executions>
<!-- Disable default execution from spring-boot-starter-parent -->
<execution>
<id>default</id>
<phase/>
</execution>
<!-- Collect git information once for multi-module projects to speed up builds -->
<execution>
<id>git-info-collect</id>
<phase>validate</phase>
<goals>
<goal>revision</goal>
</goals>
<configuration>
<skipPoms>false</skipPoms>
<runOnlyOnce>true</runOnlyOnce>
</configuration>
</execution>
<execution>
<id>git-info-properties</id>
<goals>
<goal>revision</goal>
</goals>
<configuration>
<format>properties</format>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
</configuration>
</execution>
</executions>
</plugin>
Tell us about the Plugin version used (required)
7.0.0, 8.0.2, 9.0.0
Tell us about the Maven version used (required)
Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: /home/john.doe/.sdkman/candidates/maven/current
Java version: 17.0.11, vendor: BellSoft, runtime: /home/john.doe/.sdkman/candidates/java/17.0.11-librca
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.15.146.1-microsoft-standard-wsl2", arch: "amd64", family: "unix"
Steps to Reproduce (required)
Clone repository
Run maven initialize
and check contents of generated git.properties
files
mvn clean initialize
# non-empty diff as module1's file only contains header comment
diff -u target/classes/git.properties module1/target/classes/git.properties
Re-run with version 7.0.0 of plugin
mvn clean initialize -Dgit-commit-id-maven-plugin.version=7.0.0
# no differences between the files
diff -u target/classes/git.properties module1/target/classes/git.properties
Are there any stacktraces or any error messages? (required)
WARNING You may NOT want to paste all the output that is produced with verbose
publicly,
since it MAY contain information you deem sensitive.
Review this CAREFULLY before posting your issue!
mvn clean deploy
// ????
Is there a (public) project where this issue can be reproduced? (optional)
https://github.com/KTannenberg/git-commit-id-example
Your Environment (optional)
Ubuntu 22.04.4 LTS running inside WSL2 on Windows 11
Running same steps natively on Windows 11 reproduces same bug
Context (optional)
Looking through diff between 7.0.0 and 8.0.0 I think that this commit might be a culprit - ee43e57
the same issue after update from boot 3.2 to 3.3
Thanks for the detailed report! Likely related to #700
the same issue after update from boot 3.2 to 3.3
Spring Boot 3.2.x uses version 6.0.0 of this plugin, Spring Boot 3.3.0 switches to 8.0.2 of the plugin - spring-projects/spring-boot@53f8504
Thanks again for the reproducer and indeed the problem seems to be related to the changes done in ee43e57.
The issue seems to boil down to using:
properties = new Properties(contextProperties);
instead of the previous
properties = contextProperties;
The contextProperties
are the properties that had been generated by a potential previous run and are essentially still correctly populated. The plugin will then essentially dump whatever was specified as the properties
variable.
With a
properties = new Properties(contextProperties);
the properties seem essentially empty (contextProperties are still correctly populated):
[INFO] === GitCommitIdPlugin.runPlugin(#
#Tue Jul 02 17:45:23 CEST 2024
)
I must admit that is a bit of a strange behaviour and when reading the javadoc of the properties class I still wouldn't expect such behaviour. Defaults for me sound like they should be there, but secrectly disappear....
My fix from https://github.com/git-commit-id/git-commit-id-maven-plugin/pull/760/files would propose to run:
properties = new Properties();
properties.putAll(contextProperties);
which IMHO should also do the trick.
Thanks again for the report!
Thanks @TheSnoozer, can confirm that fix works:
mvn clean initialize -Dgit-commit-id-maven-plugin.version=9.0.1 && cat commons/target/classes/git.properties job/target/classes/git.properties | grep git.commit.id
...
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.788 s
[INFO] Finished at: 2024-07-02T19:04:46+01:00
[INFO] ------------------------------------------------------------------------
git.commit.id=b509b387017ec6dbc52052fbb412698f44c5b566
git.commit.id.abbrev=b509b38
git.commit.id.describe=1.7.0-2-gb509b38
git.commit.id.describe-short=1.7.0-2
git.commit.id=b509b387017ec6dbc52052fbb412698f44c5b566
git.commit.id.abbrev=b509b38
git.commit.id.describe=1.7.0-2-gb509b38
git.commit.id.describe-short=1.7.0-2
Great, thanks for the feedback!