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