Skip to content
This repository has been archived by the owner on Apr 2, 2023. It is now read-only.

GoogleCloudPlatform/native-image-support-java

Repository files navigation

Native Image Support for Google Cloud Libraries

status: inactive

This project is no longer actively developed or maintained. If you are using version 25.4.0 or later of the libraries-bom, the Cloud Client Libraries for Java come with the native image configurations built-in. This means that the Cloud Client libraries can be compiled into native images without the need for adding the native-image-support dependency.

This repository provides support for applications using the Google Java Client Libraries to be built as GraalVM Native Images.

Setup

Add the native-image-support artifact to your project to take advantage of native image support.

For example, in Maven:

<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>native-image-support</artifactId>
    <version>0.10.0</version>
</dependency>

This dependency contains the GraalVM configurations to provide out-of-the-box support for native-image compilation of applications using Google Java Client Libraries.

Client Library Versions

To compile with native image, ensure the client library version in your project is supported by native-image-support.

Native Image Support version GraalVM Compiler Version *libraries-bom version grpc-netty-shaded version
0.10.0 >= 21.3.0 24.0.0 or later 1.42.0 or later
0.9.0 >= 21.3.0 23.x.x - 24.0.0 1.41.0
0.8.0 >= 21.2.0 23.x.x - 24.0.0 1.41.0

Typically, you can just depend on the latest versions of the client libraries to get something working if you are not sure about what versions of (transitive) dependencies are being used by your project.

NOTE: Most users typically manage their client library versions using the Cloud Libraries Bill of Materials (libraries-bom). This is an easy way to ensure that the versions of all the client libraries in your project are compatible with each other and up-to-date. The libraries-bom also manages the version of grpc-netty-shaded as well and ensures that it is at the latest compatible version.

GraalVM Features

This project offers GraalVM features which provides optional reflection configurations for specific use-cases. These features should only be used when necessary because they increase the size of the container image and increase compilation times.

  • ProtobufMessageFeature: Adds reflection metadata for request objects of the Google Cloud APIs that your application uses. This is typically only needed if you need to print/log requests objects or access them reflectively.

Add the features as an additional build argument to the native-image compiler via the --features flag.

Command line Example:

native-image -cp <other settings> --features=ProtobufMessageFeature

The Cloud Tasks code sample demonstrates how to use this setting.

Supported Libraries

Most of the Java Google Client Libraries listed here are supported for GraalVM compilation using this dependency. These libraries are all listed under the com.google.cloud group ID.

If you find an unsupported library, please make a feature request via our Github Issue Tracker.

GraalVM-compatible sample code using various Google Cloud libraries can be found below:

Google Cloud Service Library Sample Link
Cloud BigQuery bigquery-sample
Cloud BigTable bigtable-sample
Cloud Datastore datastore-sample
Cloud Firestore firestore-sample
Cloud Logging logging-sample
Cloud Pub/Sub pubsub-sample
Cloud Secret Manager secretmanager-sample
Cloud SQL (w/ MySQL) cloud-sql-sample
Cloud Spanner spanner-sample
Cloud Storage storage-sample
Cloud Tasks tasks-sample

Additional API compatibility is in active development.

Please also consult the project samples applications directory for the full range of code samples.

Additional Frameworks

Our project targets compatibility for native image frameworks as well, such as for Quarkus, Micronaut, and Spring. We are in the early stages of research for these frameworks and maintain some code samples.

We are also interested in collaborating with other open source projects to improve framework-level compatibility.

Related projects:

Please let us know if you are interested in collaborating by contacting us via our Issue Tracker.

Questions

Please report any issues and questions to our Github Issue Tracker.