java

package
v0.27.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 37 Imported by: 0

README

Java Package Developer Guide

This guide describes how to handle changes in the librarian repository that affect client library generation in google-cloud-java. It covers two scenarios:

  1. Breaking Changes: Changes that cause code generation failures, compilation errors, or integration test failures in google-cloud-java (see Handling Breaking Changes).
  2. Non-Breaking Diffs: Changes that introduce diffs in the generated code but do not break the build or tests (see Handling Changes That Cause Generation Diffs).

Handling Breaking Changes in google-cloud-java

If you are making changes in librarian that are expected to cause code generation failure or other breakages in the google-cloud-java repository (such as in the integration tests; see Example):

  1. Disable the Java Workflow: Temporarily disable the Java integration workflow by modifying java.yaml. You can do this by prepending false && to the if condition of the integration job:

    integration:
      runs-on: ubuntu-24.04
      if: false && github.event_name == 'push' && (github.ref == 'refs/heads/main')
    
  2. Add a TODO: Add a TODO comment in java.yaml linking to the GitHub issue or pull request you are working on to track the reinstate task:

    integration:
      runs-on: ubuntu-24.04
      # TODO(https://github.com/googleapis/librarian/issues/XXXX): Reinstate this job
      if: false && github.event_name == 'push' && (github.ref == 'refs/heads/main')
    
  3. Merge Librarian Changes: Merge your changes into the librarian repository.

  4. Update google-cloud-java: After the librarian changes are merged, update the google-cloud-java repository to use the pseudo-version containing your changes.

    You can update the version in librarian.yaml by running the following commands in the google-cloud-java repository:

    # Get the latest pseudo-version of librarian from main
    PSEUDO=$(GOPROXY=direct go list -m -f '{{.Version}}' github.com/googleapis/librarian@main)
    
    # Get the current librarian version used in the repo
    V=$(go run github.com/googleapis/librarian/cmd/librarian@latest config get version)
    
    # Update the version in librarian.yaml using the current tool version
    go run github.com/googleapis/librarian/cmd/librarian@${V} config set version $PSEUDO
    

    After updating the version, run generate -all to apply the changes.

  5. Reinstate the Java Workflow: Once google-cloud-java is updated and working with the new changes, remove the TODO and reinstate the java.yaml workflow.

Example of a Breaking Change

PR #6432 updated pom.xml templates. It passed local tests but broke librarian generate --all in google-cloud-java (Issue #6446). Because the integration test only runs in postsubmit, the failure wasn't caught before merge, requiring a revert (PR #6449). If anticipated, the author should have disabled the workflow beforehand.

Handling Changes That Cause Generation Diffs

If you are making changes in librarian that do not cause generation failure in google-cloud-java but will introduce a diff in the generated code:

  1. Librarian CI Stays Green: The java.yaml integration check in the librarian repository will not fail on such changes.
  2. Submit google-cloud-java PR: It is good practice to immediately open a pull request in the google-cloud-java repository. This PR should update the librarian dependency to the new pseudo-version containing your changes (using the commands described in Handling Breaking Changes) and run generate -all to apply the generated diff.
  3. Prevent Weekly Update Diffs: Proactively applying these diffs prevents them from being introduced abruptly during the weekly automated librarian updates.

Documentation

Overview

Package java provides Java specific functionality for librarian.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOmitCommonResourcesConflict is returned when OmitCommonResources is true
	// but common_resources.proto is also explicitly listed in AdditionalProtos.
	ErrOmitCommonResourcesConflict = errors.New("conflict: OmitCommonResources is true but google/cloud/common_resources.proto is explicitly listed in AdditionalProtos")
	// ErrCannotDeriveReleasedVersion is returned when released_version cannot be derived.
	ErrCannotDeriveReleasedVersion = errors.New("cannot derive released version")
)

Functions

func Add added in v0.11.0

func Add(lib *config.Library, addedAPI *config.API) (*config.Library, error)

Add initializes a new Java library with default values, or extends an existing library with a new API path, and registers the appropriate modules in versions.txt.

func ApplyMoveActionsToLibrary added in v0.26.0

func ApplyMoveActionsToLibrary(actions []moveAction, destRoot string, keepSet map[string]bool) error

ApplyMoveActionsToLibrary moves generated code to the repository directory structure, merging directories and preserving files matching the keepSet.

func Clean

func Clean(library *config.Library) error

Clean removes files in the library's output directory that are not in the keep list. It targets patterns like proto-*, grpc-*, and the main GAPIC module.

func DefaultLibraryName added in v0.11.0

func DefaultLibraryName(api string) string

DefaultLibraryName derives a default library name from an API path by stripping known prefixes (e.g., "google/cloud/", "google/api/") and returning all segments except the last one, joined by dashes.

func DefaultOutput added in v0.26.0

func DefaultOutput(name, defaultOutput string) string

DefaultOutput derives the default output directory name for a Java library.

func Fill

func Fill(library *config.Library) (*config.Library, error)

Fill populates Java-specific default values for the library from derived or documented defaults.

func FillDefaultJava added in v0.26.0

func FillDefaultJava(lib *config.Library, d *config.Default) *config.Library

FillDefaultJava populates empty Java-specific fields in lib from the config.Default, specifically from config.JavaDefault. This is typically called in sequence with Fill, which populates the derived default values.

func Format

func Format(ctx context.Context, library *config.Library) error

Format formats a Java client library using google-java-format.

func Generate

func Generate(ctx context.Context, cfg *config.Config, library *config.Library, srcs *sources.Sources) error

Generate generates a Java client library.

func IdentifyMissingModules added in v0.13.0

func IdentifyMissingModules(library *config.Library, libraryDir string) ([]string, error)

IdentifyMissingModules identifies all expected proto-*, grpc-*, client, BOM and Parent modules for the given library based on its configuration and checks for pom.xml presence on the filesystem. It returns a list of artifact IDs for the missing modules.

func Install added in v0.15.0

func Install(ctx context.Context, tools *config.Tools) error

Install installs Java tool dependencies. It creates two sibling directories: - bin/ ($LIBRARIAN_BIN/java_tools/bin) stores the generated executable wrapper scripts. - lib/ ($LIBRARIAN_BIN/java_tools/lib) isolates the downloaded compiled .jar/.exe files.

func InstallDir added in v0.24.0

func InstallDir() (string, error)

InstallDir returns the absolute path of the installation directory for Java tools.

func PostGenerate

func PostGenerate(ctx context.Context, repoPath string, cfg *config.Config) error

PostGenerate performs repository-level actions after all individual Java libraries have been generated.

func ResolveMixinDependencies added in v0.14.0

func ResolveMixinDependencies(cfg *config.Config, lib *config.Library, srcs *sources.Sources) (*config.Config, error)

ResolveMixinDependencies automatically resolves mixin dependencies for a Java library.

func Tidy

func Tidy(library *config.Library) (*config.Library, error)

Tidy tidies the Java-specific configuration for a library by removing default values.

func Validate added in v0.10.0

func Validate(cfg *config.Config) error

Validate checks that the Java-specific configuration for a library and global config is correctly formatted. It ensures that there are no conflicts in common resources configuration.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL