Skip to content

fix: make gapic-generator-java output zip timestamps deterministic#4097

Open
benjaminp wants to merge 1 commit intogoogleapis:mainfrom
benjaminp:fixed-timestamp
Open

fix: make gapic-generator-java output zip timestamps deterministic#4097
benjaminp wants to merge 1 commit intogoogleapis:mainfrom
benjaminp:fixed-timestamp

Conversation

@benjaminp
Copy link

Set a fixed timestamp on all output Jar entries. This follows the approach of Bazel's Jar creation logic.

Fixes #4096

@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Feb 4, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @benjaminp, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses the problem of non-deterministic JAR file generation in gapic-generator-java. By setting a fixed timestamp for all entries within the output JARs, the change guarantees consistent and reproducible builds, aligning with best practices for build determinism, similar to approaches used in tools like Bazel.

Highlights

  • Deterministic JAR Output: Implemented a mechanism to ensure that all generated JAR file entries have a fixed, deterministic timestamp, resolving issues with non-reproducible builds.
Changelog
  • gapic-generator-java/src/main/java/com/google/api/generator/gapic/protowriter/Writer.java
    • Added an import for java.time.LocalDateTime to support fixed timestamp generation.
    • Introduced a new private static helper method jarEntry(String name) which creates a JarEntry and sets its local time to a fixed date (January 1, 2010, 00:00:00).
    • Modified all existing JarEntry instantiations to use the new jarEntry helper method, ensuring all entries written to the JAR have the same, fixed timestamp.
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request makes the output of gapic-generator-java deterministic by setting a fixed timestamp on all entries in the generated JAR file. This is a good practice for reproducible builds. The implementation introduces a helper method to create JarEntry objects with a constant timestamp, and this is applied consistently. I have one suggestion to improve the code's readability and maintainability by extracting the hardcoded date into a named constant.

Comment on lines +234 to +239

private static JarEntry jarEntry(String name) {
JarEntry entry = new JarEntry(name);
entry.setTimeLocal(LocalDateTime.of(2010, 1, 1, 0, 0, 0));
return entry;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability and maintainability, consider extracting the magic date LocalDateTime.of(2010, 1, 1, 0, 0, 0) into a private static final constant with a descriptive name. Adding a comment explaining the choice of this date, similar to the Bazel implementation you linked, would also be beneficial. This makes the code more self-documenting.

  /**
   * The default timestamp for Jar entries. This is 2010-01-01 00:00:00 UTC.
   *
   * <p>Using a constant timestamp helps ensure that Jar files are deterministic.
   */
  private static final LocalDateTime DETERMINISTIC_JAR_TIMESTAMP =
      LocalDateTime.of(2010, 1, 1, 0, 0, 0);

  private static JarEntry jarEntry(String name) {
    JarEntry entry = new JarEntry(name);
    entry.setTimeLocal(DETERMINISTIC_JAR_TIMESTAMP);
    return entry;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gapic-generator-java embeds timestmaps in output

1 participant