-
Notifications
You must be signed in to change notification settings - Fork 49
Reproducible Builds not working when using modular jar #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I have found where the issue lies, the I have tested to add the following to the last part of the postCreateArchive() method, where the // Fix Last Modified Date of the module descriptor.
if (getLastModifiedDate() != null) {
URI uri = URI.create("jar:" + getDestFile().toURI().toString());
try (FileSystem zipfs = FileSystems.newFileSystem(uri,
new java.util.HashMap<String, Object>()) ) {
for (String path : moduleDescriptorsPath) {
Path module = zipfs.getPath(path);
long lastModDate = getLastModifiedDate().getTime();
Files.setLastModifiedTime(module, FileTime.fromMillis(lastModDate));
}
}
} This more or less works but I think the precision of the last modified time set is not the same (for some reason it's not using UTC). @hboutemy sorry if I'm pinging on you, but since the reproducible-builds is your area, without this, all the modular jars won't be reproducible never. |
There is an open issue about the jar tool breeaking this. Search JBS. |
Ok, it might be a bug on the jar tool, but probably a workaround could be implemented here, or should we wait until a new release of Java fix this? |
See my analysis here: https://issues.apache.org/jira/browse/MJAR-275 |
The root cause has been fixed in Java 18. Well, we now need a backport... |
As this doesn't seem to be backported, I could provide a workaround for this issue that should work, WDYT? IMHO depending on a specific Java release is less than ideal, not many users will use Java 18 just to compile (even if they can event target to Java 7) just to get reproducible builds. |
@jorsol You can write to the appropriate mailing list for a backport request. |
or add a jar rewriting process after the jar tool execution: notice that I did not test the update of Java 18, I don't get how the jar tool even in Java 18 will get a reproducible timestamp of the .class: IIUC, it will use the timestamp from the file system, but this timestamp is not reproducible |
I already have a working fix after the jar tool execution, that's why I'm asking if it's of interest.
In previous versions of Java, the jar tool basically rewrites the |
I think a temporary fix will be useful: if you can share yours, that would be awesome on the change, ok, if the Java 18 logic is "keep the existing thanks for the feedback @jorsol |
I just fall into a rabbit hole trying to provide a fix, after many tests and research I found other issues: The bad:
The good:
The ugly:
I think the post-processing part is not a bad trade-off to allow reproducible builds. |
What a PITA instead of Oracle monkeys fixing this the right way and back porting down to 8. Joke. |
I will open the PR as soon as the FileTime API is merged. |
The PR #205 fixes this issue if someone want to take a look 👀 . |
I just merged #199 : this is the update that I was not confident on, but everybody looks ok thanks for you patience and efforts |
Thanks @hboutemy, that update was only changing the API from the old But please, if you found something that is broken or something that needs clarification ping me to check it. Now, back to the the real fix of the reproducible build with modular jars, the PR #205 is smaller in files touched, but is actually more invasive than the previous one, this is the one that probably you should look out more closely (not saying that is should broke anything). This fix has many hours of research and it will use the new |
I have a project that compiles a module-info.java using the
<multiReleaseOutput>
approach of maven-compiler-plugin as show here:The
<project.build.outputTimestamp>
property is set on the project and the jar is created correctly, all the files set the timestamp except for the/META-INF/versions/9/module-info.class
file which causes that the build is no longer reproducible.The text was updated successfully, but these errors were encountered: