blob: c1f5c9dcd14a0a25ad9494517f8ec3e5db829c88 [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'
Carl Mastrangelo8572f5f2017-07-18 13:53:45 -070011 classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.4.0'
12 classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.11'
Eric Anderson6164b7b2017-08-26 17:10:18 -070013 classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.4"
Kun Zhang4bc2d6d2015-04-17 10:49:11 -070014 }
15}
Eric Andersonb938ba52015-02-28 09:59:25 -080016
Louis Ryan540b4d32015-09-04 13:26:24 -070017subprojects {
Eric Andersonc3e8dae2015-01-30 14:58:07 -080018 apply plugin: "checkstyle"
nathanmittler164b7342014-12-15 09:58:05 -080019 apply plugin: "java"
20 apply plugin: "maven"
nmittler52f42202015-01-21 14:30:14 -080021 apply plugin: "idea"
Eric Anderson192144e2015-03-02 13:31:14 -080022 apply plugin: "signing"
Eric Anderson041cdb12015-05-05 12:29:26 -070023 apply plugin: "jacoco"
nathanmittler164b7342014-12-15 09:58:05 -080024
Eric Anderson6164b7b2017-08-26 17:10:18 -070025 apply plugin: "me.champeau.gradle.jmh"
nmittlerc4bcf142015-09-16 15:15:10 -070026 apply plugin: "com.google.osdetector"
Eric Anderson42aa64c2017-02-02 13:48:12 -080027 // The plugin only has an effect if a signature is specified
28 apply plugin: "ru.vyarus.animalsniffer"
Eric Anderson675080b2017-02-24 14:53:23 -080029 if (!rootProject.hasProperty('errorProne') || rootProject.errorProne.toBoolean()) {
30 apply plugin: "net.ltgt.errorprone"
Eric Anderson982541b2017-04-26 13:33:27 -070031
32 dependencies {
33 // The ErrorProne plugin defaults to the latest, which would break our
34 // build if error prone releases a new version with a new check
Eric Andersoncbad9062017-07-06 17:15:20 -070035 errorprone 'com.google.errorprone:error_prone_core:2.0.21'
Eric Anderson982541b2017-04-26 13:33:27 -070036 }
37 } else {
38 // Remove per-project error-prone checker config
39 allprojects {
40 afterEvaluate { project ->
41 project.tasks.withType(JavaCompile) {
42 options.compilerArgs.removeAll { it.startsWith("-Xep:") }
43 }
44 }
45 }
Eric Anderson675080b2017-02-24 14:53:23 -080046 }
zpencer5713ebc2017-07-15 12:41:20 -070047 // TODO(zpencer): remove when intellij 2017.2 is released
48 // https://github.com/gradle/gradle/issues/2315
49 idea.module.inheritOutputDirs = true
nmittlerc4bcf142015-09-16 15:15:10 -070050
nmittlerf8314582015-01-27 10:25:39 -080051 group = "io.grpc"
zpencerab85c5a2017-08-22 12:29:03 -070052 version = "1.7.0-SNAPSHOT" // CURRENT_GRPC_VERSION
nathanmittler164b7342014-12-15 09:58:05 -080053
54 sourceCompatibility = 1.6
55 targetCompatibility = 1.6
56
57 repositories {
58 mavenCentral()
59 mavenLocal()
60 }
61
Eric Anderson6164b7b2017-08-26 17:10:18 -070062 [compileJava, compileTestJava, compileJmhJava].each() {
Eric Anderson675080b2017-02-24 14:53:23 -080063 it.options.compilerArgs += ["-Xlint:all", "-Xlint:-options", "-Xlint:-path"]
Eric Anderson76d09552015-03-12 15:25:11 -070064 it.options.encoding = "UTF-8"
Eric Anderson3c03eb72016-07-10 11:40:12 -070065 if (rootProject.hasProperty('failOnWarnings') && rootProject.failOnWarnings.toBoolean()) {
66 it.options.compilerArgs += ["-Werror"]
67 }
nmittler02c953e2015-01-26 14:03:11 -080068 }
69
Eric Anderson641cb352016-05-24 14:29:52 -070070 compileTestJava {
71 // serialVersionUID is basically guaranteed to be useless in our tests
72 options.compilerArgs += ["-Xlint:-serial"]
73 }
74
nmittler8c1d38a2015-06-01 08:31:00 -070075 jar.manifest {
76 attributes('Implementation-Title': name,
77 'Implementation-Version': version,
78 'Built-By': System.getProperty('user.name'),
79 'Built-JDK': System.getProperty('java.version'),
80 'Source-Compatibility': sourceCompatibility,
81 'Target-Compatibility': targetCompatibility)
82 }
83
Eric Anderson10fb2062015-05-05 10:28:38 -070084 javadoc.options {
85 encoding = 'UTF-8'
ZHANG Dapeng66ebcb12017-05-17 08:52:07 -070086 use = true
Eric Anderson10fb2062015-05-05 10:28:38 -070087 links 'https://docs.oracle.com/javase/8/docs/api/'
88 }
Eric Anderson14444a92015-03-11 16:44:38 -070089
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -080090 ext {
Kun Zhang6b1e7d62015-05-07 15:20:44 -070091 def exeSuffix = osdetector.os == 'windows' ? ".exe" : ""
92 protocPluginBaseName = 'protoc-gen-grpc-java'
Eric Anderson46ce4092016-01-26 12:13:06 -080093 javaPluginPath = "$rootDir/compiler/build/exe/java_plugin/$protocPluginBaseName$exeSuffix"
Kun Zhang6b1e7d62015-05-07 15:20:44 -070094
Eric Anderson97c625f2017-08-24 11:05:17 -070095 nettyVersion = '4.1.15.Final'
Eric Anderson2eeb5e32017-02-23 17:02:31 -080096 guavaVersion = '19.0'
Carl Mastrangelo24ff2742017-08-25 11:25:36 -070097 protobufVersion = '3.4.0'
98 protocVersion = protobufVersion
Kun Zhange2ed2e82016-01-27 08:26:19 -080099 protobufNanoVersion = '3.0.0-alpha-5'
Kun Zhang6b1e7d62015-05-07 15:20:44 -0700100
Kun Zhang111f6dd2015-05-05 16:11:27 -0700101 configureProtoCompilation = {
Kun Zhang35f77ee2015-06-22 16:29:30 -0700102 String generatedSourcePath = "${projectDir}/src/generated"
Kun Zhang111f6dd2015-05-05 16:11:27 -0700103 if (rootProject.childProjects.containsKey('grpc-compiler')) {
104 // Only when the codegen is built along with the project, will we be able to recompile
105 // the proto files.
106 project.apply plugin: 'com.google.protobuf'
Kun Zhang35f77ee2015-06-22 16:29:30 -0700107 project.protobuf {
108 protoc {
109 if (project.hasProperty('protoc')) {
110 path = project.protoc
111 } else {
Carl Mastrangelo0fe2c5c2017-05-23 17:04:51 -0700112 artifact = "com.google.protobuf:protoc:${protocVersion}"
Kun Zhang35f77ee2015-06-22 16:29:30 -0700113 }
114 }
115 plugins {
116 grpc {
117 path = javaPluginPath
118 }
119 }
120 generateProtoTasks {
121 all().each { task ->
122 task.dependsOn ':grpc-compiler:java_pluginExecutable'
123 // Delete the generated sources first, so that we can be alerted if they are not re-compiled.
Eric Andersone9b4d152016-04-19 11:54:04 -0700124 task.dependsOn 'deleteGeneratedSource' + task.sourceSet.name
Kun Zhang35f77ee2015-06-22 16:29:30 -0700125 // Recompile protos when the codegen has been changed
126 task.inputs.file javaPluginPath
127 // Recompile protos when build.gradle has been changed, because
128 // it's possible the version of protoc has been changed.
129 task.inputs.file "${rootProject.projectDir}/build.gradle"
130 task.plugins {
ZHANG Dapenge1091252016-07-21 16:35:18 -0700131 grpc {
132 // To generate deprecated interfaces and static bindService method,
133 // turn the enable_deprecated option to true below:
134 option 'enable_deprecated=false'
Eric Anderson182164e2016-06-16 13:54:12 -0700135 option 'noversion'
ZHANG Dapenge1091252016-07-21 16:35:18 -0700136 }
Kun Zhang2cdc5e32015-05-11 16:58:28 -0700137 }
138 }
139 }
Kun Zhang35f77ee2015-06-22 16:29:30 -0700140 generatedFilesBaseDir = generatedSourcePath
141 }
142
Eric Andersone9b4d152016-04-19 11:54:04 -0700143 sourceSets.each { sourceSet ->
Carl Mastrangeloaaf90672017-03-23 18:02:35 -0700144 task "deleteGeneratedSource${sourceSet.name}" {
145 doLast {
146 project.delete project.fileTree(dir: generatedSourcePath + '/' + sourceSet.name)
147 }
Eric Andersone9b4d152016-04-19 11:54:04 -0700148 }
Kun Zhang2cdc5e32015-05-11 16:58:28 -0700149 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700150 } else {
151 // Otherwise, we just use the checked-in generated code.
152 project.sourceSets {
153 main {
154 java {
Kun Zhang35f77ee2015-06-22 16:29:30 -0700155 srcDir "${generatedSourcePath}/main/java"
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700156 srcDir "${generatedSourcePath}/main/javanano"
Kun Zhang35f77ee2015-06-22 16:29:30 -0700157 srcDir "${generatedSourcePath}/main/grpc"
Kun Zhang287a27a2015-05-07 17:32:31 -0700158 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700159 }
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700160 test {
161 java {
162 srcDir "${generatedSourcePath}/test/java"
163 srcDir "${generatedSourcePath}/test/javanano"
164 srcDir "${generatedSourcePath}/test/grpc"
165 }
166 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700167 }
168 }
Eric Andersondbef1af2016-05-23 12:05:41 -0700169
Eric Anderson6164b7b2017-08-26 17:10:18 -0700170 [compileJava, compileTestJava, compileJmhJava].each() {
Eric Andersondbef1af2016-05-23 12:05:41 -0700171 // Protobuf-generated code produces some warnings.
Eric Anderson675080b2017-02-24 14:53:23 -0800172 // https://github.com/google/protobuf/issues/2718
173 it.options.compilerArgs += ["-Xlint:-cast", "-Xep:MissingOverride:OFF",
174 "-Xep:ReferenceEquality:OFF", "-Xep:FunctionalInterfaceClash:OFF"]
Eric Andersondbef1af2016-05-23 12:05:41 -0700175 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700176 }
177
Eric Anderson65d73c02015-05-21 11:54:04 -0700178 def epoll_suffix = "";
179 if (osdetector.classifier in ["linux-x86_64"]) {
180 // The native code is only pre-compiled on certain platforms.
181 epoll_suffix = ":" + osdetector.classifier
182 }
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800183 libraries = [
Carl Mastrangeloee12cc22017-03-22 22:09:04 -0700184 errorprone: "com.google.errorprone:error_prone_annotations:2.0.19",
Carl Mastrangelo28253612016-05-16 10:23:53 -0700185 guava: "com.google.guava:guava:${guavaVersion}",
Jeff Pinnerb1cc7cc2015-02-25 10:17:23 -0800186 hpack: 'com.twitter:hpack:0.10.1',
nmittlerb897a892015-02-23 12:03:59 -0800187 jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
Eric Gribkoff7c605102017-07-06 13:22:43 -0700188 oauth_client: 'com.google.auth:google-auth-library-oauth2-http:0.7.0',
Eric Gribkoffdf694852017-05-01 14:43:53 -0700189 google_api_protos: 'com.google.api.grpc:proto-google-common-protos:0.1.9',
Kun Zhangdef237d2016-06-14 13:51:24 -0700190 google_auth_credentials: 'com.google.auth:google-auth-library-credentials:0.4.0',
Xudong Ma6d296e82015-09-21 10:39:00 -0700191 okhttp: 'com.squareup.okhttp:okhttp:2.5.0',
Xudong Mab121c462015-09-21 12:54:06 -0700192 okio: 'com.squareup.okio:okio:1.6.0',
Bogdan Drutu482b6512017-07-11 10:13:23 -0700193 opencensus_api: 'io.opencensus:opencensus-api:0.5.1',
Yang Song4a0cf0b2017-06-06 18:16:55 -0700194 instrumentation_api: 'com.google.instrumentation:instrumentation-api:0.4.3',
Kun Zhangc5b94c72015-05-06 16:44:55 -0700195 protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
Eric Andersona8700a72016-07-29 11:57:41 -0700196 protobuf_lite: "com.google.protobuf:protobuf-lite:3.0.1",
Eric Andersonb1d72e52016-09-27 17:15:12 -0700197 protoc_lite: "com.google.protobuf:protoc-gen-javalite:3.0.0",
Kun Zhangbd23a8d2015-08-28 18:47:06 -0700198 protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${protobufNanoVersion}",
Carl Mastrangelod34260a2017-07-14 12:35:14 -0700199 protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.8.1',
Carl Mastrangelo8e1fba72016-03-02 09:30:35 -0800200 protobuf_util: "com.google.protobuf:protobuf-java-util:${protobufVersion}",
nathanmittler164b7342014-12-15 09:58:05 -0800201
Łukasz Strzałkowski67eefa62017-05-15 10:57:43 -0700202 netty: "io.netty:netty-codec-http2:[${nettyVersion}]",
203 netty_epoll: "io.netty:netty-transport-native-epoll:${nettyVersion}" + epoll_suffix,
204 netty_proxy_handler: "io.netty:netty-handler-proxy:${nettyVersion}",
Eric Anderson97c625f2017-08-24 11:05:17 -0700205 netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:2.0.6.Final',
nathanmittler164b7342014-12-15 09:58:05 -0800206
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800207 // Test dependencies.
208 junit: 'junit:junit:4.11',
Carl Mastrangelob3bc7fc2016-04-01 15:18:23 -0700209 mockito: 'org.mockito:mockito-core:1.9.5',
Louis Ryana7049bc2016-03-23 13:18:04 -0700210 truth: 'com.google.truth:truth:0.28',
211
212 // Benchmark dependencies
213 hdrhistogram: 'org.hdrhistogram:HdrHistogram:2.1.8',
214 math: 'org.apache.commons:commons-math3:3.6',
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700215
216 // Jetty ALPN dependencies
Eric Anderson308b6ea2017-03-13 10:13:42 -0700217 jetty_alpn_agent: 'org.mortbay.jetty.alpn:jetty-alpn-agent:2.0.6'
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800218 ]
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800219 }
nathanmittler164b7342014-12-15 09:58:05 -0800220
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700221 // Define a separate configuration for managing the dependency on Jetty ALPN agent.
nmittler74cfe6c2015-05-22 12:25:10 -0700222 configurations {
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700223 alpnagent
nmittler74cfe6c2015-05-22 12:25:10 -0700224 }
225
nathanmittler164b7342014-12-15 09:58:05 -0800226 dependencies {
227 testCompile libraries.junit,
228 libraries.mockito
nmittler74cfe6c2015-05-22 12:25:10 -0700229
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700230 // Configuration for modules that use Jetty ALPN agent
231 alpnagent libraries.jetty_alpn_agent
Eric Anderson6164b7b2017-08-26 17:10:18 -0700232
233 jmh 'org.openjdk.jmh:jmh-core:1.19',
234 'org.openjdk.jmh:jmh-generator-bytecode:1.19'
nathanmittler164b7342014-12-15 09:58:05 -0800235 }
Eric Anderson192144e2015-03-02 13:31:14 -0800236
237 signing {
238 required false
239 sign configurations.archives
240 }
241
nmittler732cfc02015-03-03 07:59:13 -0800242 // Disable JavaDoc doclint on Java 8. It's annoying.
243 if (JavaVersion.current().isJava8Compatible()) {
244 allprojects {
245 tasks.withType(Javadoc) {
246 options.addStringOption('Xdoclint:none', '-quiet')
247 }
248 }
249 }
250
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800251 checkstyle {
Eric Andersone6d00622017-07-07 10:57:03 -0700252 configFile = file("$rootDir/buildscripts/checkstyle.xml")
Eric Anderson6ab27ab2016-04-18 09:15:25 -0700253 toolVersion = "6.17"
Eric Andersonad44f0a2015-05-05 08:54:51 -0700254 ignoreFailures = false
Eric Anderson26141b42015-03-21 10:59:17 -0700255 if (rootProject.hasProperty("checkstyle.ignoreFailures")) {
256 ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean()
257 }
Eric Andersonefa774b2015-09-15 10:34:14 -0700258 configProperties["rootDir"] = rootDir
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800259 }
260
261 checkstyleMain {
Kun Zhang693a7d22015-05-06 11:35:08 -0700262 source = fileTree(dir: "src/main", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800263 }
264
265 checkstyleTest {
Kun Zhang693a7d22015-05-06 11:35:08 -0700266 source = fileTree(dir: "src/test", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800267 }
268
Eric Anderson6164b7b2017-08-26 17:10:18 -0700269 jmh {
270 warmupIterations = 10
271 iterations = 10
272 fork = 1
273 // None of our benchmarks need the tests, and we have pseudo-circular
274 // dependencies that break when including them. (context's testCompile
275 // depends on core; core's testCompile depends on testing)
276 includeTests = false
277 }
278
Eric Anderson192144e2015-03-02 13:31:14 -0800279 task javadocJar(type: Jar) {
280 classifier = 'javadoc'
281 from javadoc
282 }
283
284 task sourcesJar(type: Jar) {
285 classifier = 'sources'
286 from sourceSets.main.allSource
287 }
288
289 artifacts {
290 archives javadocJar, sourcesJar
291 }
292
293 uploadArchives.repositories.mavenDeployer {
294 beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
zhangkun83da3c3f82015-03-11 18:03:31 -0700295 String stagingUrl
Kun Zhang2f749712015-05-06 13:10:28 -0700296 if (rootProject.hasProperty('repositoryId')) {
297 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
298 rootProject.repositoryId
zhangkun83da3c3f82015-03-11 18:03:31 -0700299 } else {
300 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
301 }
Kun Zhang2f749712015-05-06 13:10:28 -0700302 def configureAuth = {
303 if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
304 authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
305 }
Eric Anderson192144e2015-03-02 13:31:14 -0800306 }
Kun Zhang2f749712015-05-06 13:10:28 -0700307 repository(url: stagingUrl, configureAuth)
308 snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
Eric Anderson192144e2015-03-02 13:31:14 -0800309 }
Carl Mastrangelo4988d8b2017-01-19 12:48:55 -0800310 uploadArchives.onlyIf { !name.contains("thrift") }
Eric Anderson192144e2015-03-02 13:31:14 -0800311
312 [
313 install.repositories.mavenInstaller,
314 uploadArchives.repositories.mavenDeployer,
315 ]*.pom*.whenConfigured { pom ->
316 pom.project {
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700317 name "$project.group:$project.name"
Eric Anderson192144e2015-03-02 13:31:14 -0800318 description project.description
319 url 'https://github.com/grpc/grpc-java'
320
321 scm {
Eric Andersonb7354952016-04-08 08:37:07 -0700322 connection 'scm:git:https://github.com/grpc/grpc-java.git'
323 developerConnection 'scm:git:git@github.com:grpc/grpc-java.git'
Eric Anderson192144e2015-03-02 13:31:14 -0800324 url 'https://github.com/grpc/grpc-java'
325 }
326
327 licenses {
328 license {
Carl Mastrangelo7b97df02017-05-31 14:37:42 -0700329 name 'Apache 2.0'
330 url 'https://opensource.org/licenses/Apache-2.0'
Eric Anderson192144e2015-03-02 13:31:14 -0800331 }
332 }
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700333
334 developers {
335 developer {
336 id "grpc.io"
337 name "gRPC Contributors"
338 email "grpc-io@googlegroups.com"
Mehrdad Afshari8ce0bc22017-07-10 22:48:17 +0000339 url "https://grpc.io/"
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700340 // https://issues.gradle.org/browse/GRADLE-2719
Carl Mastrangelo3bfd6302017-05-31 13:29:01 -0700341 organization = "gRPC Authors"
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700342 organizationUrl "https://www.google.com"
343 }
344 }
Eric Anderson192144e2015-03-02 13:31:14 -0800345 }
Eric Anderson90db93b2016-04-08 13:47:30 -0700346 if (!(project.name in
Naveen Reddy Chedeti28609592016-07-28 08:48:27 -0700347 ["grpc-stub", "grpc-protobuf", "grpc-protobuf-lite", "grpc-protobuf-nano", "grpc-thrift"])) {
Eric Anderson90db93b2016-04-08 13:47:30 -0700348 def core = pom.dependencies.find {dep -> dep.artifactId == 'grpc-core'}
349 if (core != null) {
350 // Depend on specific version of grpc-core because internal package is unstable
351 core.version = "[" + core.version + "]"
352 }
353 }
Eric Anderson192144e2015-03-02 13:31:14 -0800354 }
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700355 // At a test failure, log the stack trace to the console so that we don't
356 // have to open the HTML in a browser.
357 test {
358 testLogging {
359 exceptionFormat = 'full'
nmittler4ee2a652015-06-01 16:20:08 -0700360 showExceptions true
361 showCauses true
362 showStackTraces true
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700363 }
Eric Anderson56dca032016-02-12 08:48:41 -0800364 maxHeapSize = '1500m'
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700365 }
nathanmittler164b7342014-12-15 09:58:05 -0800366}