blob: 6316c5f0e8ad7ffcde7f1dfff96085f9dd016f0e [file] [log] [blame]
Kun Zhang4bc2d6d2015-04-17 10:49:11 -07001buildscript {
2 repositories {
3 mavenCentral()
4 mavenLocal()
Eric Anderson675080b2017-02-24 14:53:23 -08005 maven {
6 url "https://plugins.gradle.org/m2/"
7 }
Kun Zhang4bc2d6d2015-04-17 10:49:11 -07008 }
9 dependencies {
nmittlerc4bcf142015-09-16 15:15:10 -070010 classpath 'com.google.gradle:osdetector-gradle-plugin:1.4.0'
Eric Anderson675080b2017-02-24 14:53:23 -080011 classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.2.0'
12 classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.9'
Kun Zhang4bc2d6d2015-04-17 10:49:11 -070013 }
14}
Eric Andersonb938ba52015-02-28 09:59:25 -080015
Louis Ryan540b4d32015-09-04 13:26:24 -070016subprojects {
Eric Andersonc3e8dae2015-01-30 14:58:07 -080017 apply plugin: "checkstyle"
nathanmittler164b7342014-12-15 09:58:05 -080018 apply plugin: "java"
19 apply plugin: "maven"
nmittler52f42202015-01-21 14:30:14 -080020 apply plugin: "idea"
Eric Anderson192144e2015-03-02 13:31:14 -080021 apply plugin: "signing"
Eric Anderson041cdb12015-05-05 12:29:26 -070022 apply plugin: "jacoco"
nathanmittler164b7342014-12-15 09:58:05 -080023
nmittlerc4bcf142015-09-16 15:15:10 -070024 apply plugin: "com.google.osdetector"
Eric Anderson42aa64c2017-02-02 13:48:12 -080025 // The plugin only has an effect if a signature is specified
26 apply plugin: "ru.vyarus.animalsniffer"
Eric Anderson675080b2017-02-24 14:53:23 -080027 if (!rootProject.hasProperty('errorProne') || rootProject.errorProne.toBoolean()) {
28 apply plugin: "net.ltgt.errorprone"
Eric Anderson982541b2017-04-26 13:33:27 -070029
30 dependencies {
31 // The ErrorProne plugin defaults to the latest, which would break our
32 // build if error prone releases a new version with a new check
33 errorprone 'com.google.errorprone:error_prone_core:2.0.19'
34 }
35 } else {
36 // Remove per-project error-prone checker config
37 allprojects {
38 afterEvaluate { project ->
39 project.tasks.withType(JavaCompile) {
40 options.compilerArgs.removeAll { it.startsWith("-Xep:") }
41 }
42 }
43 }
Eric Anderson675080b2017-02-24 14:53:23 -080044 }
nmittlerc4bcf142015-09-16 15:15:10 -070045
nmittlerf8314582015-01-27 10:25:39 -080046 group = "io.grpc"
Carl Mastrangelo17b90162017-04-11 14:51:39 -070047 version = "1.4.0-SNAPSHOT" // CURRENT_GRPC_VERSION
nathanmittler164b7342014-12-15 09:58:05 -080048
49 sourceCompatibility = 1.6
50 targetCompatibility = 1.6
51
52 repositories {
53 mavenCentral()
54 mavenLocal()
55 }
56
Eric Anderson76d09552015-03-12 15:25:11 -070057 [compileJava, compileTestJava].each() {
Eric Anderson675080b2017-02-24 14:53:23 -080058 it.options.compilerArgs += ["-Xlint:all", "-Xlint:-options", "-Xlint:-path"]
Eric Anderson76d09552015-03-12 15:25:11 -070059 it.options.encoding = "UTF-8"
Eric Anderson3c03eb72016-07-10 11:40:12 -070060 if (rootProject.hasProperty('failOnWarnings') && rootProject.failOnWarnings.toBoolean()) {
61 it.options.compilerArgs += ["-Werror"]
62 }
nmittler02c953e2015-01-26 14:03:11 -080063 }
64
Eric Anderson641cb352016-05-24 14:29:52 -070065 compileTestJava {
66 // serialVersionUID is basically guaranteed to be useless in our tests
67 options.compilerArgs += ["-Xlint:-serial"]
68 }
69
nmittler8c1d38a2015-06-01 08:31:00 -070070 jar.manifest {
71 attributes('Implementation-Title': name,
72 'Implementation-Version': version,
73 'Built-By': System.getProperty('user.name'),
74 'Built-JDK': System.getProperty('java.version'),
75 'Source-Compatibility': sourceCompatibility,
76 'Target-Compatibility': targetCompatibility)
77 }
78
Eric Anderson10fb2062015-05-05 10:28:38 -070079 javadoc.options {
80 encoding = 'UTF-8'
ZHANG Dapeng66ebcb12017-05-17 08:52:07 -070081 use = true
Eric Anderson10fb2062015-05-05 10:28:38 -070082 links 'https://docs.oracle.com/javase/8/docs/api/'
83 }
Eric Anderson14444a92015-03-11 16:44:38 -070084
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -080085 ext {
Kun Zhang6b1e7d62015-05-07 15:20:44 -070086 def exeSuffix = osdetector.os == 'windows' ? ".exe" : ""
87 protocPluginBaseName = 'protoc-gen-grpc-java'
Eric Anderson46ce4092016-01-26 12:13:06 -080088 javaPluginPath = "$rootDir/compiler/build/exe/java_plugin/$protocPluginBaseName$exeSuffix"
Kun Zhang6b1e7d62015-05-07 15:20:44 -070089
Łukasz Strzałkowski67eefa62017-05-15 10:57:43 -070090 nettyVersion = '4.1.11.Final'
Eric Anderson2eeb5e32017-02-23 17:02:31 -080091 guavaVersion = '19.0'
Carl Mastrangelob0323ac2017-02-07 09:47:15 -080092 protobufVersion = '3.2.0'
Kun Zhange2ed2e82016-01-27 08:26:19 -080093 protobufNanoVersion = '3.0.0-alpha-5'
Kun Zhang6b1e7d62015-05-07 15:20:44 -070094
Kun Zhang111f6dd2015-05-05 16:11:27 -070095 configureProtoCompilation = {
Kun Zhang35f77ee2015-06-22 16:29:30 -070096 String generatedSourcePath = "${projectDir}/src/generated"
Kun Zhang111f6dd2015-05-05 16:11:27 -070097 if (rootProject.childProjects.containsKey('grpc-compiler')) {
98 // Only when the codegen is built along with the project, will we be able to recompile
99 // the proto files.
100 project.apply plugin: 'com.google.protobuf'
Kun Zhang35f77ee2015-06-22 16:29:30 -0700101 project.protobuf {
102 protoc {
103 if (project.hasProperty('protoc')) {
104 path = project.protoc
105 } else {
106 artifact = "com.google.protobuf:protoc:${protobufVersion}"
107 }
108 }
109 plugins {
110 grpc {
111 path = javaPluginPath
112 }
113 }
114 generateProtoTasks {
115 all().each { task ->
116 task.dependsOn ':grpc-compiler:java_pluginExecutable'
117 // Delete the generated sources first, so that we can be alerted if they are not re-compiled.
Eric Andersone9b4d152016-04-19 11:54:04 -0700118 task.dependsOn 'deleteGeneratedSource' + task.sourceSet.name
Kun Zhang35f77ee2015-06-22 16:29:30 -0700119 // Recompile protos when the codegen has been changed
120 task.inputs.file javaPluginPath
121 // Recompile protos when build.gradle has been changed, because
122 // it's possible the version of protoc has been changed.
123 task.inputs.file "${rootProject.projectDir}/build.gradle"
124 task.plugins {
ZHANG Dapenge1091252016-07-21 16:35:18 -0700125 grpc {
126 // To generate deprecated interfaces and static bindService method,
127 // turn the enable_deprecated option to true below:
128 option 'enable_deprecated=false'
129 }
Kun Zhang2cdc5e32015-05-11 16:58:28 -0700130 }
131 }
132 }
Kun Zhang35f77ee2015-06-22 16:29:30 -0700133 generatedFilesBaseDir = generatedSourcePath
134 }
135
Eric Andersone9b4d152016-04-19 11:54:04 -0700136 sourceSets.each { sourceSet ->
Carl Mastrangeloaaf90672017-03-23 18:02:35 -0700137 task "deleteGeneratedSource${sourceSet.name}" {
138 doLast {
139 project.delete project.fileTree(dir: generatedSourcePath + '/' + sourceSet.name)
140 }
Eric Andersone9b4d152016-04-19 11:54:04 -0700141 }
Kun Zhang2cdc5e32015-05-11 16:58:28 -0700142 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700143 } else {
144 // Otherwise, we just use the checked-in generated code.
145 project.sourceSets {
146 main {
147 java {
Kun Zhang35f77ee2015-06-22 16:29:30 -0700148 srcDir "${generatedSourcePath}/main/java"
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700149 srcDir "${generatedSourcePath}/main/javanano"
Kun Zhang35f77ee2015-06-22 16:29:30 -0700150 srcDir "${generatedSourcePath}/main/grpc"
Kun Zhang287a27a2015-05-07 17:32:31 -0700151 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700152 }
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700153 test {
154 java {
155 srcDir "${generatedSourcePath}/test/java"
156 srcDir "${generatedSourcePath}/test/javanano"
157 srcDir "${generatedSourcePath}/test/grpc"
158 }
159 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700160 }
161 }
Eric Andersondbef1af2016-05-23 12:05:41 -0700162
Eric Gribkoffc8c9fff2016-11-28 13:20:55 -0800163 [compileJava, compileTestJava].each() {
Eric Andersondbef1af2016-05-23 12:05:41 -0700164 // Protobuf-generated code produces some warnings.
Eric Anderson675080b2017-02-24 14:53:23 -0800165 // https://github.com/google/protobuf/issues/2718
166 it.options.compilerArgs += ["-Xlint:-cast", "-Xep:MissingOverride:OFF",
167 "-Xep:ReferenceEquality:OFF", "-Xep:FunctionalInterfaceClash:OFF"]
Eric Andersondbef1af2016-05-23 12:05:41 -0700168 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700169 }
170
Eric Anderson65d73c02015-05-21 11:54:04 -0700171 def epoll_suffix = "";
172 if (osdetector.classifier in ["linux-x86_64"]) {
173 // The native code is only pre-compiled on certain platforms.
174 epoll_suffix = ":" + osdetector.classifier
175 }
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800176 libraries = [
Carl Mastrangeloee12cc22017-03-22 22:09:04 -0700177 errorprone: "com.google.errorprone:error_prone_annotations:2.0.19",
Carl Mastrangelo28253612016-05-16 10:23:53 -0700178 guava: "com.google.guava:guava:${guavaVersion}",
Jeff Pinnerb1cc7cc2015-02-25 10:17:23 -0800179 hpack: 'com.twitter:hpack:0.10.1',
nmittlerb897a892015-02-23 12:03:59 -0800180 jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
Kun Zhangdef237d2016-06-14 13:51:24 -0700181 oauth_client: 'com.google.auth:google-auth-library-oauth2-http:0.4.0',
Eric Gribkoffdf694852017-05-01 14:43:53 -0700182 google_api_protos: 'com.google.api.grpc:proto-google-common-protos:0.1.9',
Kun Zhangdef237d2016-06-14 13:51:24 -0700183 google_auth_credentials: 'com.google.auth:google-auth-library-credentials:0.4.0',
Xudong Ma6d296e82015-09-21 10:39:00 -0700184 okhttp: 'com.squareup.okhttp:okhttp:2.5.0',
Xudong Mab121c462015-09-21 12:54:06 -0700185 okio: 'com.squareup.okio:okio:1.6.0',
Kun Zhang49bde542017-04-25 13:53:29 -0700186 instrumentation_api: 'com.google.instrumentation:instrumentation-api:0.4.2',
Kun Zhangc5b94c72015-05-06 16:44:55 -0700187 protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
Eric Andersona8700a72016-07-29 11:57:41 -0700188 // swap to ${protobufVersion} after versions align again
189 protobuf_lite: "com.google.protobuf:protobuf-lite:3.0.1",
Eric Andersonb1d72e52016-09-27 17:15:12 -0700190 // swap to ${protobufVersion} after versions align again
191 protoc_lite: "com.google.protobuf:protoc-gen-javalite:3.0.0",
Kun Zhangbd23a8d2015-08-28 18:47:06 -0700192 protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${protobufNanoVersion}",
Kun Zhang9d747bb2016-08-18 13:06:18 -0700193 protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.8.0',
Carl Mastrangelo8e1fba72016-03-02 09:30:35 -0800194 protobuf_util: "com.google.protobuf:protobuf-java-util:${protobufVersion}",
nathanmittler164b7342014-12-15 09:58:05 -0800195
Łukasz Strzałkowski67eefa62017-05-15 10:57:43 -0700196 netty: "io.netty:netty-codec-http2:[${nettyVersion}]",
197 netty_epoll: "io.netty:netty-transport-native-epoll:${nettyVersion}" + epoll_suffix,
198 netty_proxy_handler: "io.netty:netty-handler-proxy:${nettyVersion}",
199 netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:2.0.1.Final',
nathanmittler164b7342014-12-15 09:58:05 -0800200
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800201 // Test dependencies.
202 junit: 'junit:junit:4.11',
Carl Mastrangelob3bc7fc2016-04-01 15:18:23 -0700203 mockito: 'org.mockito:mockito-core:1.9.5',
Louis Ryana7049bc2016-03-23 13:18:04 -0700204 truth: 'com.google.truth:truth:0.28',
205
206 // Benchmark dependencies
207 hdrhistogram: 'org.hdrhistogram:HdrHistogram:2.1.8',
208 math: 'org.apache.commons:commons-math3:3.6',
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700209
210 // Jetty ALPN dependencies
Eric Anderson308b6ea2017-03-13 10:13:42 -0700211 jetty_alpn_agent: 'org.mortbay.jetty.alpn:jetty-alpn-agent:2.0.6'
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800212 ]
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800213 }
nathanmittler164b7342014-12-15 09:58:05 -0800214
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700215 // Define a separate configuration for managing the dependency on Jetty ALPN agent.
nmittler74cfe6c2015-05-22 12:25:10 -0700216 configurations {
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700217 alpnagent
nmittler74cfe6c2015-05-22 12:25:10 -0700218 }
219
nathanmittler164b7342014-12-15 09:58:05 -0800220 dependencies {
221 testCompile libraries.junit,
222 libraries.mockito
nmittler74cfe6c2015-05-22 12:25:10 -0700223
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700224 // Configuration for modules that use Jetty ALPN agent
225 alpnagent libraries.jetty_alpn_agent
nathanmittler164b7342014-12-15 09:58:05 -0800226 }
Eric Anderson192144e2015-03-02 13:31:14 -0800227
228 signing {
229 required false
230 sign configurations.archives
231 }
232
nmittler732cfc02015-03-03 07:59:13 -0800233 // Disable JavaDoc doclint on Java 8. It's annoying.
234 if (JavaVersion.current().isJava8Compatible()) {
235 allprojects {
236 tasks.withType(Javadoc) {
237 options.addStringOption('Xdoclint:none', '-quiet')
238 }
239 }
240 }
241
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800242 checkstyle {
243 configFile = file("$rootDir/checkstyle.xml")
Eric Anderson6ab27ab2016-04-18 09:15:25 -0700244 toolVersion = "6.17"
Eric Andersonad44f0a2015-05-05 08:54:51 -0700245 ignoreFailures = false
Eric Anderson26141b42015-03-21 10:59:17 -0700246 if (rootProject.hasProperty("checkstyle.ignoreFailures")) {
247 ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean()
248 }
Eric Andersonefa774b2015-09-15 10:34:14 -0700249 configProperties["rootDir"] = rootDir
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800250 }
251
252 checkstyleMain {
Kun Zhang693a7d22015-05-06 11:35:08 -0700253 source = fileTree(dir: "src/main", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800254 }
255
256 checkstyleTest {
Kun Zhang693a7d22015-05-06 11:35:08 -0700257 source = fileTree(dir: "src/test", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800258 }
259
Eric Anderson192144e2015-03-02 13:31:14 -0800260 task javadocJar(type: Jar) {
261 classifier = 'javadoc'
262 from javadoc
263 }
264
265 task sourcesJar(type: Jar) {
266 classifier = 'sources'
267 from sourceSets.main.allSource
268 }
269
270 artifacts {
271 archives javadocJar, sourcesJar
272 }
273
274 uploadArchives.repositories.mavenDeployer {
275 beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
zhangkun83da3c3f82015-03-11 18:03:31 -0700276 String stagingUrl
Kun Zhang2f749712015-05-06 13:10:28 -0700277 if (rootProject.hasProperty('repositoryId')) {
278 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
279 rootProject.repositoryId
zhangkun83da3c3f82015-03-11 18:03:31 -0700280 } else {
281 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
282 }
Kun Zhang2f749712015-05-06 13:10:28 -0700283 def configureAuth = {
284 if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
285 authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
286 }
Eric Anderson192144e2015-03-02 13:31:14 -0800287 }
Kun Zhang2f749712015-05-06 13:10:28 -0700288 repository(url: stagingUrl, configureAuth)
289 snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
Eric Anderson192144e2015-03-02 13:31:14 -0800290 }
Carl Mastrangelo4988d8b2017-01-19 12:48:55 -0800291 uploadArchives.onlyIf { !name.contains("thrift") }
Eric Anderson192144e2015-03-02 13:31:14 -0800292
293 [
294 install.repositories.mavenInstaller,
295 uploadArchives.repositories.mavenDeployer,
296 ]*.pom*.whenConfigured { pom ->
297 pom.project {
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700298 name "$project.group:$project.name"
Eric Anderson192144e2015-03-02 13:31:14 -0800299 description project.description
300 url 'https://github.com/grpc/grpc-java'
301
302 scm {
Eric Andersonb7354952016-04-08 08:37:07 -0700303 connection 'scm:git:https://github.com/grpc/grpc-java.git'
304 developerConnection 'scm:git:git@github.com:grpc/grpc-java.git'
Eric Anderson192144e2015-03-02 13:31:14 -0800305 url 'https://github.com/grpc/grpc-java'
306 }
307
308 licenses {
309 license {
310 name 'BSD 3-Clause'
311 url 'http://opensource.org/licenses/BSD-3-Clause'
312 }
313 }
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700314
315 developers {
316 developer {
317 id "grpc.io"
318 name "gRPC Contributors"
319 email "grpc-io@googlegroups.com"
320 url "http://grpc.io/"
321 // https://issues.gradle.org/browse/GRADLE-2719
322 organization = "Google, Inc."
323 organizationUrl "https://www.google.com"
324 }
325 }
Eric Anderson192144e2015-03-02 13:31:14 -0800326 }
Eric Anderson90db93b2016-04-08 13:47:30 -0700327 if (!(project.name in
Naveen Reddy Chedeti28609592016-07-28 08:48:27 -0700328 ["grpc-stub", "grpc-protobuf", "grpc-protobuf-lite", "grpc-protobuf-nano", "grpc-thrift"])) {
Eric Anderson90db93b2016-04-08 13:47:30 -0700329 def core = pom.dependencies.find {dep -> dep.artifactId == 'grpc-core'}
330 if (core != null) {
331 // Depend on specific version of grpc-core because internal package is unstable
332 core.version = "[" + core.version + "]"
333 }
334 }
Eric Anderson192144e2015-03-02 13:31:14 -0800335 }
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700336 // At a test failure, log the stack trace to the console so that we don't
337 // have to open the HTML in a browser.
338 test {
339 testLogging {
340 exceptionFormat = 'full'
nmittler4ee2a652015-06-01 16:20:08 -0700341 showExceptions true
342 showCauses true
343 showStackTraces true
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700344 }
Eric Anderson56dca032016-02-12 08:48:41 -0800345 maxHeapSize = '1500m'
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700346 }
nathanmittler164b7342014-12-15 09:58:05 -0800347}