xref: /aosp_15_r20/external/grpc-grpc-java/examples/build.gradle (revision e07d83d3ffcef9ecfc9f7f475418ec639ff0e5fe)
1plugins {
2    // Provide convenience executables for trying out the examples.
3    id 'application'
4    id 'com.google.protobuf' version '0.9.1'
5    // Generate IntelliJ IDEA's .idea & .iml project files
6    id 'idea'
7}
8
9repositories {
10    maven { // The google mirror is less flaky than mavenCentral()
11        url "https://maven-central.storage-download.googleapis.com/maven2/" }
12    mavenCentral()
13    mavenLocal()
14}
15
16sourceCompatibility = 1.8
17targetCompatibility = 1.8
18
19// IMPORTANT: You probably want the non-SNAPSHOT version of gRPC. Make sure you
20// are looking at a tagged version of the example and not "master"!
21
22// Feel free to delete the comment at the next line. It is just for safely
23// updating the version in our release process.
24def grpcVersion = '1.56.1-SNAPSHOT' // CURRENT_GRPC_VERSION
25def protobufVersion = '3.22.3'
26def protocVersion = protobufVersion
27
28dependencies {
29    implementation "io.grpc:grpc-protobuf:${grpcVersion}"
30    implementation "io.grpc:grpc-services:${grpcVersion}"
31    implementation "io.grpc:grpc-stub:${grpcVersion}"
32    compileOnly "org.apache.tomcat:annotations-api:6.0.53"
33
34    // examples/advanced need this for JsonFormat
35    implementation "com.google.protobuf:protobuf-java-util:${protobufVersion}"
36
37    runtimeOnly "io.grpc:grpc-netty-shaded:${grpcVersion}"
38
39    testImplementation "io.grpc:grpc-testing:${grpcVersion}"
40    testImplementation "junit:junit:4.13.2"
41    testImplementation "org.mockito:mockito-core:3.4.0"
42}
43
44protobuf {
45    protoc { artifact = "com.google.protobuf:protoc:${protocVersion}" }
46    plugins {
47        grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" }
48    }
49    generateProtoTasks {
50        all()*.plugins { grpc {} }
51    }
52}
53
54// Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code.
55sourceSets {
56    main {
57        java {
58            srcDirs 'build/generated/source/proto/main/grpc'
59            srcDirs 'build/generated/source/proto/main/java'
60        }
61    }
62}
63
64startScripts.enabled = false
65
66// Creates start scripts for a class name and adds it to the distribution. The
67// base class name is used to name the task and scripts. For example, passed
68// the class io.grpc.examples.helloworld.HelloWorldClient, it creates the task
69// helloWorldClient with script name hello-world-client.
70def createStartScripts(String mainClassName) {
71    String bareName = mainClassName.substring(mainClassName.lastIndexOf('.') + 1);
72    String taskName = bareName.uncapitalize();
73    def newTask = tasks.register(taskName, CreateStartScripts) {
74        mainClass = mainClassName
75        applicationName = taskName.replaceAll('([A-Z])') { '-' + it[0].uncapitalize() }
76        outputDir = new File(project.buildDir, 'tmp/scripts/' + name)
77        classpath = startScripts.classpath
78    }
79    applicationDistribution.into('bin') {
80        from(newTask)
81        fileMode = 0755
82    }
83}
84
85createStartScripts('io.grpc.examples.advanced.HelloJsonClient')
86createStartScripts('io.grpc.examples.advanced.HelloJsonServer')
87createStartScripts('io.grpc.examples.cancellation.CancellationClient')
88createStartScripts('io.grpc.examples.cancellation.CancellationServer')
89createStartScripts('io.grpc.examples.customloadbalance.CustomLoadBalanceClient')
90createStartScripts('io.grpc.examples.deadline.DeadlineClient')
91createStartScripts('io.grpc.examples.deadline.DeadlineServer')
92createStartScripts('io.grpc.examples.errordetails.ErrorDetailsExample')
93createStartScripts('io.grpc.examples.experimental.CompressingHelloWorldClient')
94createStartScripts('io.grpc.examples.grpcproxy.GrpcProxy')
95createStartScripts('io.grpc.examples.healthservice.HealthServiceClient')
96createStartScripts('io.grpc.examples.healthservice.HealthServiceServer')
97createStartScripts('io.grpc.examples.hedging.HedgingHelloWorldClient')
98createStartScripts('io.grpc.examples.hedging.HedgingHelloWorldServer')
99createStartScripts('io.grpc.examples.helloworld.HelloWorldClient')
100createStartScripts('io.grpc.examples.helloworld.HelloWorldServer')
101createStartScripts('io.grpc.examples.keepalive.KeepAliveClient')
102createStartScripts('io.grpc.examples.keepalive.KeepAliveServer')
103createStartScripts('io.grpc.examples.loadbalance.LoadBalanceClient')
104createStartScripts('io.grpc.examples.loadbalance.LoadBalanceServer')
105createStartScripts('io.grpc.examples.manualflowcontrol.ManualFlowControlClient')
106createStartScripts('io.grpc.examples.manualflowcontrol.ManualFlowControlServer')
107createStartScripts('io.grpc.examples.multiplex.MultiplexingServer')
108createStartScripts('io.grpc.examples.multiplex.SharingClient')
109createStartScripts('io.grpc.examples.nameresolve.NameResolveClient')
110createStartScripts('io.grpc.examples.nameresolve.NameResolveServer')
111createStartScripts('io.grpc.examples.retrying.RetryingHelloWorldClient')
112createStartScripts('io.grpc.examples.retrying.RetryingHelloWorldServer')
113createStartScripts('io.grpc.examples.routeguide.RouteGuideClient')
114createStartScripts('io.grpc.examples.routeguide.RouteGuideServer')
115createStartScripts('io.grpc.examples.waitforready.WaitForReadyClient')
116