Update the build.gradle file, add dependencies and the protobuf plugin
for Gradle. The introduction and guide for protobuf-gradle-plugin can be
found here.
applyplugin:'java'applyplugin:'com.google.protobuf'repositories{mavenCentral()}// updating the version in our release process.defgrpcVersion='1.8.0'// CURRENT_GRPC_VERSIONdefnettyTcNativeVersion='2.0.7.Final'dependencies{compile"com.google.api.grpc:proto-google-common-protos:0.1.9"compile"io.grpc:grpc-netty:${grpcVersion}"compile"io.grpc:grpc-protobuf:${grpcVersion}"compile"io.grpc:grpc-stub:${grpcVersion}"compile"io.netty:netty-tcnative-boringssl-static:${nettyTcNativeVersion}"compile"org.bouncycastle:bcmail-jdk15:1.46"testCompile"io.grpc:grpc-testing:${grpcVersion}"testCompile"junit:junit:4.12"testCompile"org.mockito:mockito-core:1.9.5"}buildscript{repositories{mavenCentral()}dependencies{// ASSUMES GRADLE 2.12 OR HIGHER. Use plugin version 0.7.5 with earlier// gradle versionsclasspath'com.google.protobuf:protobuf-gradle-plugin:0.8.1'}}protobuf{protoc{artifact='com.google.protobuf:protoc:3.4.0'}plugins{grpc{artifact="io.grpc:protoc-gen-grpc-java:${grpcVersion}"}}generateProtoTasks{all()*.plugins{grpc{}}}}// Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code.sourceSets{main{java{srcDirs'build/generated/source/proto/main/grpc'srcDirs'build/generated/source/proto/main/java'}}}// Generate IntelliJ IDEA's .idea & .iml project filesapplyplugin:'idea'// Provide convenience executables for trying out the examples.applyplugin:'application'startScripts.enabled=false
Run the following command to build the library and auto-generate code from
protoc build plugin:
./gradlewbuild
To enable TLS on the server, under src/main/certificates/ the
following files are required:
server_cert_chain.pem your server certificate chain in PEM format
server_private_key.pem your private key for the server certificate
chain, needs to be the PKCS#8 private key
trusted_client_roots.pem the root certificates that are trusted
when authenticating clients, you can choose to obtain this set of
trusted roots from an authority like
Mozilla, or install the set
of roots currently recommended by the Google Internet Authority
G2. In the latter case, you may have
to manually update the root certificate at times
place the BookingService.java under
src/main/java/ext/maps/booking/partner/v2, place Health.java under
src/main/java/grpc/health/v1. In both files, follow the TODOs to
complete your implementations.
Update the gradle.build file to specify the generation of server executable
by adding the following code:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-05-20 UTC."],[[["\u003cp\u003eA skeleton gRPC server is available for download to aid in the implementation of a complete gRPC server.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves setting up a Java Gradle project, including adding dependencies, the protobuf plugin, and defining necessary .proto files for booking service and health checks.\u003c/p\u003e\n"],["\u003cp\u003eTLS encryption can be enabled on the server using certificate chain, private key, and trusted client root files.\u003c/p\u003e\n"],["\u003cp\u003eSample code from the repository is required to implement specific service files while completing TODOs.\u003c/p\u003e\n"],["\u003cp\u003eThe build process involves using Gradle to compile, generate code, and install the distribution for running the booking server.\u003c/p\u003e\n"]]],["To begin, download the booking service and health check protocol files into the `src/main/proto` directory of your Java Gradle project. Update `build.gradle` with necessary dependencies and the protobuf plugin. Build the library with `./gradlew build`, generating code from the protocol buffers. For TLS, place server certificates and trusted client roots under `src/main/certificates`. Retrieve and modify the sample `BookingService.java` and `Health.java` files. Finally, configure the server executable in `gradle.build`, compile, and run it.\n"],null,["# gRPC Server Skeleton for Java\n\nYou can download our [skeleton gRPC server](https://maps-booking.googlesource.com/java-maps-booking-grpc-server-skeleton/)\nto help get started with implementing your complete gRPC server.\n\n### Get Started\n\n1. Create a java gradle project (grpc-booking-service), under the src/main,\n create a 'proto' directory.\n\n2. Download the [booking service\n definition](https://developers.google.com/actions-center/download/apitemplate.v2.booking_service.proto)\n and [health checking\n protocol](https://github.com/grpc/grpc/blob/master/src/proto/grpc/health/v1/health.proto),\n place them under src/main/proto. These files define the gRPC methods and\n messages for the Actions Center API and Health Check.\n\n3. Update the ***build.gradle*** file, add dependencies and the protobuf plugin\n for Gradle. The introduction and guide for protobuf-gradle-plugin can be\n found [here](https://github.com/google/protobuf-gradle-plugin).\n\n apply plugin: 'java'\n apply plugin: 'com.google.protobuf'\n\n repositories {\n mavenCentral()\n }\n\n // updating the version in our release process.\n def grpcVersion = '1.8.0' // CURRENT_GRPC_VERSION\n def nettyTcNativeVersion = '2.0.7.Final'\n\n dependencies {\n compile \"com.google.api.grpc:proto-google-common-protos:0.1.9\"\n compile \"io.grpc:grpc-netty:${grpcVersion}\"\n compile \"io.grpc:grpc-protobuf:${grpcVersion}\"\n compile \"io.grpc:grpc-stub:${grpcVersion}\"\n compile \"io.netty:netty-tcnative-boringssl-static:${nettyTcNativeVersion}\"\n compile \"org.bouncycastle:bcmail-jdk15:1.46\"\n\n testCompile \"io.grpc:grpc-testing:${grpcVersion}\"\n testCompile \"junit:junit:4.12\"\n testCompile \"org.mockito:mockito-core:1.9.5\"\n }\n\n buildscript {\n repositories {\n mavenCentral()\n }\n dependencies {\n // ASSUMES GRADLE 2.12 OR HIGHER. Use plugin version 0.7.5 with earlier\n // gradle versions\n classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.1'\n }\n }\n\n protobuf {\n protoc {\n artifact = 'com.google.protobuf:protoc:3.4.0'\n }\n plugins {\n grpc {\n artifact = \"io.grpc:protoc-gen-grpc-java:${grpcVersion}\"\n }\n }\n generateProtoTasks {\n all()*.plugins {\n grpc {}\n }\n }\n }\n\n // Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code.\n sourceSets {\n main {\n java {\n srcDirs 'build/generated/source/proto/main/grpc'\n srcDirs 'build/generated/source/proto/main/java'\n }\n }\n }\n\n // Generate IntelliJ IDEA's .idea & .iml project files\n apply plugin: 'idea'\n\n // Provide convenience executables for trying out the examples.\n apply plugin: 'application'\n\n startScripts.enabled = false\n\n4. Run the following command to build the library and auto-generate code from\n protoc build plugin:\n\n ./gradlew build\n\n5. To enable TLS on the server, under ***src/main/certificates/*** the\n following files are required:\n\n - ***server_cert_chain.pem*** your server certificate chain in PEM format\n - ***server_private_key.pem*** your private key for the server certificate chain, needs to be the PKCS#8 private key\n - ***trusted_client_roots.pem*** the root certificates that are trusted when authenticating clients, you can choose to obtain this set of trusted roots from an authority like [Mozilla](https://wiki.mozilla.org/CA:IncludedCAs), or install the [set\n of roots currently recommended by the Google Internet Authority\n G2](https://pki.goog/roots.pem). In the latter case, you may have to manually update the root certificate at times\n6. Retrieve the sample code from this repo:\n\n git clone https://maps-booking.googlesource.com/java-maps-booking-grpc-server-skeleton\n\n place the **BookingService.java** under\n *src/main/java/ext/maps/booking/partner/v2* , place **Health.java** under\n *src/main/java/grpc/health/v1* . In both files, follow the ***TODOs*** to\n complete your implementations.\n7. Update the gradle.build file to specify the generation of server executable\n by adding the following code:\n\n task bookingService(type: CreateStartScripts) {\n mainClassName = 'ext.maps.booking.partner.v2.BookingService'\n applicationName = 'booking-service'\n outputDir = new File(project.buildDir, 'tmp')\n classpath = jar.outputs.files + project.configurations.runtime\n }\n\n applicationDistribution.into('bin') {\n from(bookingService)\n fileMode = 0755\n }\n\n8. Compile the server:\n\n ./gradlew installDist\n\n9. Run the booking server:\n\n ./build/install/grpc-booking-service/bin/booking-service\n\n### Final Directory Structure\n\n src\n |---main\n |---certificates\n |---server_cert_chain.pem\n |---server_private_key.pem\n |---trusted_client_roots.pem\n |---java\n |---ext.maps.booking.partner.v2.BookingService.java\n |---grpc.health.v1.Health.java\n |---proto\n |---booking_service.proto\n |---health.proto\n |---test\n\n### Other Reference\n\n- For other building tools, visit the\n [gRPC-java](https://grpc.io/docs/quickstart/java.html) and download the\n example, check grpc-java/examples.\n\n git clone -b v1.9.0 https://github.com/grpc/grpc-java\n\n- [gRPC java Transport Security\n (TLS)](https://github.com/grpc/grpc-java/blob/master/SECURITY.md).\n\n- [gRPC API\n V2](https://developers.google.com/actions-center/reference/grpc-api-v2/slot-specification)."]]