Repository navigation
Closed
Description
Describe the bug (required)
in https://maven.apache.org/guides/mini/guide-reproducible-builds.html it is mentioned that you could do <project.build.outputTimestamp>${git.commit.time}</project.build.outputTimestamp> and this is IMHO indeed a neat idea.
If you do so, however, you'll get
[ERROR] Failed to execute goal io.github.git-commit-id:git-commit-id-maven-plugin:6.0.0:revision (get-the-git-infos) on project mautstation: Invalid 'project.build.outputTimestamp' value '2023-11-30T09:17:06+0100': Unparseable date: "2023-11-30T09:17:06+0100" -> [Help 1]
This is because the defaullt dateFormat is yyyy-MM-dd'T'HH:mm:ssZ but parseOutputTimestamp only tries to parse the format yyyy-MM-dd'T'HH:mm:ssXXX
It can be work-arounded by specifying the configuration <dateFormat>yyyy-MM-dd'T'HH:mm:ssXXX</dateFormat> but this shouldnt be neccessary.
Tell us about your plugin configuration (required)
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>6.0.0</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
</configuration>
</plugin>
Tell us about the Plugin version used (required)
6.0.0
Tell us about the Maven version used (required)
mvn --version
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: C:\Users\chris\AppData\Local\Programs\IntelliJ IDEA Ultimate\plugins\maven\lib\maven3
Java version: 17.0.2, vendor: Oracle Corporation, runtime: C:\java\openjdk-17.0.2
Default locale: de_DE, platform encoding: UTF-8
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"Steps to Reproduce (required)
just configure the property <project.build.outputTimestamp>${git.commit.time}</project.build.outputTimestamp> in the POM
Are there any stacktraces or any error messages? (required)
Caused by: pl.project13.core.GitCommitIdExecutionException: Invalid 'project.build.outputTimestamp' value '2023-11-30T09:17:06+0100'
at pl.project13.maven.git.GitCommitIdMojo.parseOutputTimestamp (GitCommitIdMojo.java:1511)
at pl.project13.maven.git.GitCommitIdMojo$2.getReproducibleBuildOutputTimestamp (GitCommitIdMojo.java:1336)
at pl.project13.core.GitCommitIdPlugin.loadBuildData (GitCommitIdPlugin.java:335)
at pl.project13.core.GitCommitIdPlugin.runPlugin (GitCommitIdPlugin.java:295)
at pl.project13.maven.git.GitCommitIdMojo.execute (GitCommitIdMojo.java:1453)Is there a (public) project where this issue can be reproduced? (optional)
No response
Your Environment (optional)
No response
Context (optional)
No response
Activity
Interessierter commentedon Dec 4, 2023
I could do an MR but I am unsure how to proceed.... IMHO the
parseOutputTimestampmethod should use the configureddateFormatfor parsing but maybe there were reasons to use a hardcoded format? A relatively safe option would be to leave the existing two attempts as is and do a 3rd attempt with the configured dateFormat - WDYT?TheSnoozer commentedon Dec 4, 2023
Mhh this is a weird one.
The page https://maven.apache.org/guides/mini/guide-reproducible-builds.html mentions the following should be supported:
Which aligns with https://maven.apache.org/ref/3.3.1/maven-model-builder/ that states that the
maven.build.timestampthat will also be outputted asyyyy-MM-dd'T'HH:mm:ss'Z'. The format can apparently be overwritten bymaven.build.timestamp.format.When clicking on the somewhat hidden link in (Enable Reproducible Builds mode for plugins, by adding project.build.outputTimestamp property to the project's pom.xml) mentioned in https://maven.apache.org/guides/mini/guide-reproducible-builds.html one comes across the following:
a For Maven 2.x and 3.x, the value can be defined as an equivalent property:
So I guess here is one source of this secret
XXX-Format.When now checking the code of the plugin:
git-commit-id-maven-plugin/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java
Lines 1484 to 1496 in fd67b7e
I see in the commentary that this was inspired by https://github.com/apache/maven-archiver/blob/a3103d99396cd8d3440b907ef932a33563225265/src/main/java/org/apache/maven/archiver/MavenArchiver.java#L765.
Here we have again the same/similar pattern of
yyyy-MM-dd'T'HH:mm:ssXXXA more recent version got rid of this hard-coded string:
https://github.com/apache/maven-archiver/blob/cc2f6a219f6563f450b0c00e8ccd651520b67406/src/main/java/org/apache/maven/archiver/MavenArchiver.java#L755
So I would suggest to use a similar parsing mechanism and drop the pattern with
yyyy-MM-dd'T'HH:mm:ssXXX. Thus the entire parsing should IMHO look like:Of course I think it also makes sense to update the comments to mention an
yyyy-MM-dd'T'HH:mm:ssXXXformat to refer just to ISO 8601. For example:git-commit-id-maven-plugin/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java
Line 1125 in fd67b7e
Does this make sense?
Could you create a PR and add relevant tests?
Thanks :-)
Interessierter commentedon Feb 12, 2024
I finally got some time to look into this again. Unfortunately your suggestion does not work as (also new to me) the new java date parsers are not able to parse the RFC 822 format?!
I then went ahead and modified the last lines of https://github.com/git-commit-id/git-commit-id-maven-plugin/blob/master/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java#L1464
to be the following (i.e. just re-try parsing it using the format the timestamp is created with from git);
this worked for this plugin, unfortunately then later on in my project the
spring-boot-maven-pluginfails because it also cannot handle the RFC822 timestamp https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java#L157 ;(I thought that maybe using the format
yyyy-MM-dd'T'HH:mm:ssXXXas default for the commit timestamp would be most useful way to continue and changed https://github.com/git-commit-id/git-commit-id-maven-plugin/blob/master/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java#L513 but to my surprise this did not work, I still got the error from the Spring Boot plugin above, only setting it explicitly in the git plugins configuration did work, is it possible that this default value isn't used but there is another default value in the project that is actually using the values (git-commit-id-plugin-core-6.0.0-rc.6.jar)?Ultimately I am unsure how to proceed and will stick with the workaround I am currently configured (explicitly configuring a working format in the plugins configurion in pom.xml)
#674: parse 'project.build.outputTimestamp' formatted as ISO 8601
TheSnoozer commentedon Feb 12, 2024
The time must be formatted as ISO 8601. Can you check if the code in https://github.com/git-commit-id/git-commit-id-maven-plugin/pull/699/files would cover your case?
Interessierter commentedon Feb 13, 2024
Thank you very much for your response!
Unfortunately it does not, as (maybe this was not clear enough in my ramblings above) the plugin itself generates an invalid dateformat for further maven processing (as seen here: https://github.com/git-commit-id/git-commit-id-maven-plugin/blob/master/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java#L513). I cobbled together a quick reproducer project:
git-plugin-timestamp-problem-demo.zip
git initin that dirgit add .in that dirgit commit -m "initial commit"in that dirmvn clean packageto see the build failThis is caused because I set the
project.build.outputTimestampto the plugins value (line 18 in pom.xml) - which is the heart of the reproducible build feature. If I explicitly set the output format to ISO8601 (commented out line 54 in the pom.xml) all is well. An like I said: just changing line 513 in GitCommitIdMojo is not enough, the plugin still generates an "invalid" format, it has to be set explicitly in the configuration.TheSnoozer commentedon Feb 13, 2024
Thanks for the additional explanations and the reproducer! Sorry maybe it was just me being slow in understanding what you really mean, but I think I got it now.
Essentially you would like to pass in any time-formatted values that are produced by the plugin like
<project.build.outputTimestamp>${git.commit.time}</project.build.outputTimestamp>.For that to happen (without any extra
<dateFormat>yyyy-MM-dd'T'HH:mm:ssXXX</dateFormat>) the default value of thedateFormatwould need to be changed (see https://github.com/git-commit-id/git-commit-id-maven-plugin/blob/master/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java#L513).Likely this would mean it's a breaking change, since as a plugin developer I don't know what weird features the plugin users rely on...
Interessierter commentedon Feb 14, 2024
no worries :) As I said in my original message, doing
<project.build.outputTimestamp>${git.commit.time}</project.build.outputTimestamp>is explicitly mentioned on Mavens reproducible build page (last item in FAQ) as this enables truly automatic reproducible builds but then this clashes with the "historic" dateformat of this plugin, which could not be consumed by the plugin itself (until your changes from #699 are applied) but also cause problems in other Maven plugins (like the not-so-seldomly-used spring-boot-maven-plugin`` and maybe others) because they too expect ISO8601 instead of RFC822 format.So IMHO yes, you should do a breaking change as the "new" default is more sensible - this could clearly be advertised in the release notes and so on ("default format changed, if you need the old format add
<dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>as configuration").Also, like I said above, I did exactly this locally (i.e. changed line 513 in GitCommitIdMojo to be
@Parameter(defaultValue = "yyyy-MM-dd'T'HH:mm:ssXXX")) and installed SNAPSHOT version locally and used that and it had no effect, the timestamp was still in RFC822 format so there addtionally may be a bug somewhere (unfortunately I have no knowledge on how to debug a maven plugin and the "real work" is done in the other project (git-commit-id-plugin-core-6.0.0-rc.6) which I did not checkout)#674: breaking: change dateFormat from RFC 822 time to ISO 8601
TheSnoozer commentedon Feb 14, 2024
No worries, just to make sure I don't overlook something I ran a quick test and setting the
@Parameter(defaultValue = "yyyy-MM-dd'T'HH:mm:ssXXX"). It indeed does the trick, so maybe you still had/have adateFormatencoded in your pom.xml (remember the plugin just suggests a default, everything can be overwritten by the user).I have tested #699 with the demo profile that is encoded in the pom:
With a configuration of:
this produces a
2024-02-14T10:06:03-08:00which is a valid ISO 8601 representation.Interessierter commentedon Feb 15, 2024
It does not work on my machine :( I see that your changes should be good in theory but there's something wrong with it, I did the following, where is the mistake (could you try it on your environment):
%USERPROFILE%\.m2\repository\io\github\git-commit-id\git-commit-id-maven-plugin\directory)mvn clean installed the plugin, checked that it does appear again in the maven repoI can see it in the plugins output that the wrong value is generated:
What am I missing/doing wrong?? Again thank you for your investigations and effort, I really appreciate it 👍
TheSnoozer commentedon Feb 15, 2024
Mhhh.
The following sounds interesting in your error log:
That for me sounds like
org.apache.maven.plugins:maven-jar-plugincan not deal with the Text '2024-02-15T13:54:59+0100'. However that test/date is conform with ISO8601.The support for reproducible builds (ISO8601) should have been added to the maven-jar-plugin in version 3.2.X (via https://issues.apache.org/jira/browse/MJAR-263) and you are using the latest available version (3.3.0).
The documentation of the maven-jar-plugin (https://github.com/apache/maven-jar-plugin/blob/63f9c982d49f046519088490d7a8af5a7cd647fb/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java#L144) even claims it can process '2019-10-05T20:37:42+06:00'.
Maybe I'm going insane, but i think it would be worth to try your setup entirely WITHOUT the git-commit-id plugin.
So Instead of
<project.build.outputTimestamp>${git.commit.time}</project.build.outputTimestamp>try the hard-coded<project.build.outputTimestamp>2024-02-15T13:54:59+0100</project.build.outputTimestamp>.I'll try to troubleshoot this further with your reproducer too...
TheSnoozer commentedon Feb 15, 2024
I have stripped down your demo project to a really minimal thing.
Got rid of the plugin, got rid of spring-boot (just to rule out any funky things) and hard-coded
<project.build.outputTimestamp>2024-02-15T13:54:59+0100</project.build.outputTimestamp>(because why not we are experimenting).Project:
git-plugin-timestamp-problem-demo_minimal.zip
Congratulation, you found an issue in the maven-jar-plugin! :-)
TheSnoozer commentedon Feb 15, 2024
Ohhhhhh we produce the time as
2024-02-15T13:54:59+0100, however with a extra colon in the TZ like2024-02-15T13:54:59+01:00it works.Created https://issues.apache.org/jira/browse/MJAR-301.
TheSnoozer commentedon Feb 15, 2024
Could you perhaps also experiment why your java version reports the time as 2024-02-15T13:54:59+0100 (without the
:)?The plugin should run roughtly the following:
As per https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html#iso8601timezone the
XXXshould report asSign TwoDigitHours : MinutesNotes to myself:
https://github.com/FasterXML/ jackson-modules-java8 /issues/ 38
https://copyprogramming.com/howto/java-time-datetimeformatter-pattern-for-timezone-offset
michael-o commentedon Feb 15, 2024
Read my answer in the JIRA issue. Straight away:
2024-02-15T13:54:59+0100is invalid input because it does not comply with the extended date time offset format. Git devs fucked up back then and then they could not fix it anymore and were forced to introduce strict ISO 8601.Interessierter commentedon Feb 16, 2024
thanks for your feedback, let' recapitulate (I am in Germany so I use my timezone as an example):
2024-02-15T13:54:59+0100is RFC822-format which is produced by the SimpleDateFormat (SDF) format stringyyyy-MM-dd'T'HH:mm:ssZ2024-02-15T13:54:59+01:00is ISO8601-format which is produced by the SDF format stringyyyy-MM-dd'T'HH:mm:ssXXX(there is an additional colon seperating the minutes from the hoursI would not have used the same words as @michael-o but yeah, using RFC822-format as default output format from the git-commit-id-plugin was probably not a good choice and should be changed in the next release to ISO8601 (see also my reasoning above and I am under the impression that you agree to that)
I still have the issue that, when used, the updated plugin does not work as expected, I am really lost at this as I have no knowledge how maven is doing things:
pl.project13.maven.git.GitCommitIdMojo#execute()method, just above theGitCommitIdPlugin.runPlugininvocation (its line 1415 locally):mvn clean package -Pdemo -DskipTestsI see that the output isthat is exactly like I would expect it to be and how it should be
<dateFormat>configuration in the POM and I have the<project.build.outputTimestamp>${git.commit.time}</project.build.outputTimestamp>property set, the output is the followingWTF is going on?! Where is he getting the wrong dateformat again from?? It must be set somewhere by some black Maven magic that I do know nothing of ;( I tried to debug it setting field watchpoint on
pl.project13.maven.git.GitCommitIdMojo#dateFormatthen running the demo profile in the plugin itself but it wasnt invoked. Do you have any idea??TheSnoozer commentedon Feb 16, 2024
Thanks everyone for your input.
First of all, I agree the plugin should change to ISO8601-formatted dates.
When running with
mvn -XI see the following:My theory or the black maven magic that makes your date formatted like a
0100comes I believe from your parent pom:https://github.com/spring-projects/spring-boot/blob/4fd0e29cc8719bda72e0e67c2392fd48e7b4009d/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/build.gradle#L151
I guess this should be changed to
yyyy-MM-dd'T'HH:mm:ssXXXChange dateformat for git-commit-id-maven-plugin
Merge pull request #699 from git-commit-id/674
TheSnoozer commentedon Feb 28, 2024
Thanks again for the report and your patience with me.
The sprint boot has updated the default format to
yyyy-MM-dd'T'HH:mm:ssXXX(see here).I also just merged the changes in the plugin to update to the same format.
So thanks again, I'm going ahead and close the ticket now :-)