Summary
Add a command line option to the jar
and jmod
tools to specify the timestamp to use for new and updated entries.
Problem
With the ever increasing requirement for reproducible builds, it is required for JDK tooling such as jar and jmod to produce deterministic output from the same input content. Currently, jar and jmod tools timestamp all generated entries with the current local time and use the last modified timestamps of source files.
Solution
Add a new option --date=<ISO-8601 extended offset date-time with optional time-zone>, which will timestamp using the specified date&time instant localized to UTC for all created or updated entries. The localizing of the specified date&time to UTC allows the option to produce the same content from the same instant in time, when built across different time zones, given that the zip extended DOS time is time zone unaware and is stored as a localized date&time.
The current ZipEntry API provides no time zone aware APIs for setting the entry times, thus this solution relies on the extended DOS time localization, which limits the valid date range to 1980->2099. As such the new --date option will enforce validation that the specified timestamp localized to UTC falls within this valid range.
OpenJDK and other build environments utilizing the jar or jmod tools can then leverage this option to achieve deterministic JAR and JMOD files.
Specification
jar --date=<ISO-8601 extended offset date-time with optional time-zone>
jmod --date=<ISO-8601 extended offset date-time with optional time-zone>
The ISO-8601 date&time stamp must be an ISO 8601 date and time, with a time-zone offset and an optional zone, eg:
- YYYY-MM-DD'T'HH:MM:SS'+/-'HH:MM['zone']
- YYYY-MM-DD'T'HH:MM:SS'+/-'HH:MM
- YYYY-MM-DD'T'HH:MM:SS'Z'
The following restrictions apply:
- The ISO 8601 string must represent an instant in time between 1980-01-01T00:00:02Z and 2099-12-31T23:59:59Z, inclusive. Values outside this range result in an error.
- The ISO 8601 string must have a precision to at least the minute value and must include a time offset. Representations with reduced precision result in an error.
- The extended format of ISO 8601 is required. The basic format which omits the separators ("-" and ":") results in an error.
The jar and jmod JDK tooling for any created or updated ZIP entries, will set the entry extended DOS time to the specified time instant localized to UTC, rounding down the instant to an even number of seconds, discarding any milliseconds or nanoseconds.
Example:
jar --create --date="2021-01-06T14:36:00+02:00" --file=classes.jar Foo.class
zipinfo -v classes.jar | grep "last modified" :
file last modified on (DOS date/time): 2021 Jan 6 12:36:00
- csr of
-
JDK-8276766 Enable jar and jmod to produce deterministic timestamped content
- Resolved
- relates to
-
JDK-8279048 javadoc support for reproducible builds
- Closed
- links to
-
Review openjdk/jdk/6481