blob: 1692c27d46e8523fffab46a2694ac577e767ea74 [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 Mastrangelocc5343a2017-07-05 18:32:35 -070011 classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.3.0'
Carl Mastrangelo1da1dba2017-06-07 17:18:44 -070012 classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.10'
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
Eric Andersoncbad9062017-07-06 17:15:20 -070033 errorprone 'com.google.errorprone:error_prone_core:2.0.21'
Eric Anderson982541b2017-04-26 13:33:27 -070034 }
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 }
zpencer5713ebc2017-07-15 12:41:20 -070045 // TODO(zpencer): remove when intellij 2017.2 is released
46 // https://github.com/gradle/gradle/issues/2315
47 idea.module.inheritOutputDirs = true
nmittlerc4bcf142015-09-16 15:15:10 -070048
nmittlerf8314582015-01-27 10:25:39 -080049 group = "io.grpc"
Carl Mastrangelo424eeea2017-07-06 10:43:56 -070050 version = "1.6.0-SNAPSHOT" // CURRENT_GRPC_VERSION
nathanmittler164b7342014-12-15 09:58:05 -080051
52 sourceCompatibility = 1.6
53 targetCompatibility = 1.6
54
55 repositories {
56 mavenCentral()
57 mavenLocal()
58 }
59
Eric Anderson76d09552015-03-12 15:25:11 -070060 [compileJava, compileTestJava].each() {
Eric Anderson675080b2017-02-24 14:53:23 -080061 it.options.compilerArgs += ["-Xlint:all", "-Xlint:-options", "-Xlint:-path"]
Eric Anderson76d09552015-03-12 15:25:11 -070062 it.options.encoding = "UTF-8"
Eric Anderson3c03eb72016-07-10 11:40:12 -070063 if (rootProject.hasProperty('failOnWarnings') && rootProject.failOnWarnings.toBoolean()) {
64 it.options.compilerArgs += ["-Werror"]
65 }
nmittler02c953e2015-01-26 14:03:11 -080066 }
67
Eric Anderson641cb352016-05-24 14:29:52 -070068 compileTestJava {
69 // serialVersionUID is basically guaranteed to be useless in our tests
70 options.compilerArgs += ["-Xlint:-serial"]
71 }
72
nmittler8c1d38a2015-06-01 08:31:00 -070073 jar.manifest {
74 attributes('Implementation-Title': name,
75 'Implementation-Version': version,
76 'Built-By': System.getProperty('user.name'),
77 'Built-JDK': System.getProperty('java.version'),
78 'Source-Compatibility': sourceCompatibility,
79 'Target-Compatibility': targetCompatibility)
80 }
81
Eric Anderson10fb2062015-05-05 10:28:38 -070082 javadoc.options {
83 encoding = 'UTF-8'
ZHANG Dapeng66ebcb12017-05-17 08:52:07 -070084 use = true
Eric Anderson10fb2062015-05-05 10:28:38 -070085 links 'https://docs.oracle.com/javase/8/docs/api/'
86 }
Eric Anderson14444a92015-03-11 16:44:38 -070087
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -080088 ext {
Kun Zhang6b1e7d62015-05-07 15:20:44 -070089 def exeSuffix = osdetector.os == 'windows' ? ".exe" : ""
90 protocPluginBaseName = 'protoc-gen-grpc-java'
Eric Anderson46ce4092016-01-26 12:13:06 -080091 javaPluginPath = "$rootDir/compiler/build/exe/java_plugin/$protocPluginBaseName$exeSuffix"
Kun Zhang6b1e7d62015-05-07 15:20:44 -070092
Carl Mastrangelo7207a9f2017-07-10 15:02:03 -070093 nettyVersion = '4.1.13.Final'
Eric Anderson2eeb5e32017-02-23 17:02:31 -080094 guavaVersion = '19.0'
Carl Mastrangelo0fe2c5c2017-05-23 17:04:51 -070095 protobufVersion = '3.3.1'
96 protocVersion = '3.3.0' // TODO(carl-mastrangelo): set this from protobufVersion when versions align again
Kun Zhange2ed2e82016-01-27 08:26:19 -080097 protobufNanoVersion = '3.0.0-alpha-5'
Kun Zhang6b1e7d62015-05-07 15:20:44 -070098
Kun Zhang111f6dd2015-05-05 16:11:27 -070099 configureProtoCompilation = {
Kun Zhang35f77ee2015-06-22 16:29:30 -0700100 String generatedSourcePath = "${projectDir}/src/generated"
Kun Zhang111f6dd2015-05-05 16:11:27 -0700101 if (rootProject.childProjects.containsKey('grpc-compiler')) {
102 // Only when the codegen is built along with the project, will we be able to recompile
103 // the proto files.
104 project.apply plugin: 'com.google.protobuf'
Kun Zhang35f77ee2015-06-22 16:29:30 -0700105 project.protobuf {
106 protoc {
107 if (project.hasProperty('protoc')) {
108 path = project.protoc
109 } else {
Carl Mastrangelo0fe2c5c2017-05-23 17:04:51 -0700110 artifact = "com.google.protobuf:protoc:${protocVersion}"
Kun Zhang35f77ee2015-06-22 16:29:30 -0700111 }
112 }
113 plugins {
114 grpc {
115 path = javaPluginPath
116 }
117 }
118 generateProtoTasks {
119 all().each { task ->
120 task.dependsOn ':grpc-compiler:java_pluginExecutable'
121 // Delete the generated sources first, so that we can be alerted if they are not re-compiled.
Eric Andersone9b4d152016-04-19 11:54:04 -0700122 task.dependsOn 'deleteGeneratedSource' + task.sourceSet.name
Kun Zhang35f77ee2015-06-22 16:29:30 -0700123 // Recompile protos when the codegen has been changed
124 task.inputs.file javaPluginPath
125 // Recompile protos when build.gradle has been changed, because
126 // it's possible the version of protoc has been changed.
127 task.inputs.file "${rootProject.projectDir}/build.gradle"
128 task.plugins {
ZHANG Dapenge1091252016-07-21 16:35:18 -0700129 grpc {
130 // To generate deprecated interfaces and static bindService method,
131 // turn the enable_deprecated option to true below:
132 option 'enable_deprecated=false'
133 }
Kun Zhang2cdc5e32015-05-11 16:58:28 -0700134 }
135 }
136 }
Kun Zhang35f77ee2015-06-22 16:29:30 -0700137 generatedFilesBaseDir = generatedSourcePath
138 }
139
Eric Andersone9b4d152016-04-19 11:54:04 -0700140 sourceSets.each { sourceSet ->
Carl Mastrangeloaaf90672017-03-23 18:02:35 -0700141 task "deleteGeneratedSource${sourceSet.name}" {
142 doLast {
143 project.delete project.fileTree(dir: generatedSourcePath + '/' + sourceSet.name)
144 }
Eric Andersone9b4d152016-04-19 11:54:04 -0700145 }
Kun Zhang2cdc5e32015-05-11 16:58:28 -0700146 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700147 } else {
148 // Otherwise, we just use the checked-in generated code.
149 project.sourceSets {
150 main {
151 java {
Kun Zhang35f77ee2015-06-22 16:29:30 -0700152 srcDir "${generatedSourcePath}/main/java"
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700153 srcDir "${generatedSourcePath}/main/javanano"
Kun Zhang35f77ee2015-06-22 16:29:30 -0700154 srcDir "${generatedSourcePath}/main/grpc"
Kun Zhang287a27a2015-05-07 17:32:31 -0700155 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700156 }
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700157 test {
158 java {
159 srcDir "${generatedSourcePath}/test/java"
160 srcDir "${generatedSourcePath}/test/javanano"
161 srcDir "${generatedSourcePath}/test/grpc"
162 }
163 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700164 }
165 }
Eric Andersondbef1af2016-05-23 12:05:41 -0700166
Eric Gribkoffc8c9fff2016-11-28 13:20:55 -0800167 [compileJava, compileTestJava].each() {
Eric Andersondbef1af2016-05-23 12:05:41 -0700168 // Protobuf-generated code produces some warnings.
Eric Anderson675080b2017-02-24 14:53:23 -0800169 // https://github.com/google/protobuf/issues/2718
170 it.options.compilerArgs += ["-Xlint:-cast", "-Xep:MissingOverride:OFF",
171 "-Xep:ReferenceEquality:OFF", "-Xep:FunctionalInterfaceClash:OFF"]
Eric Andersondbef1af2016-05-23 12:05:41 -0700172 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700173 }
174
Eric Anderson65d73c02015-05-21 11:54:04 -0700175 def epoll_suffix = "";
176 if (osdetector.classifier in ["linux-x86_64"]) {
177 // The native code is only pre-compiled on certain platforms.
178 epoll_suffix = ":" + osdetector.classifier
179 }
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800180 libraries = [
Carl Mastrangeloee12cc22017-03-22 22:09:04 -0700181 errorprone: "com.google.errorprone:error_prone_annotations:2.0.19",
Carl Mastrangelo28253612016-05-16 10:23:53 -0700182 guava: "com.google.guava:guava:${guavaVersion}",
Jeff Pinnerb1cc7cc2015-02-25 10:17:23 -0800183 hpack: 'com.twitter:hpack:0.10.1',
nmittlerb897a892015-02-23 12:03:59 -0800184 jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
Eric Gribkoff7c605102017-07-06 13:22:43 -0700185 oauth_client: 'com.google.auth:google-auth-library-oauth2-http:0.7.0',
Eric Gribkoffdf694852017-05-01 14:43:53 -0700186 google_api_protos: 'com.google.api.grpc:proto-google-common-protos:0.1.9',
Kun Zhangdef237d2016-06-14 13:51:24 -0700187 google_auth_credentials: 'com.google.auth:google-auth-library-credentials:0.4.0',
Xudong Ma6d296e82015-09-21 10:39:00 -0700188 okhttp: 'com.squareup.okhttp:okhttp:2.5.0',
Xudong Mab121c462015-09-21 12:54:06 -0700189 okio: 'com.squareup.okio:okio:1.6.0',
Bogdan Drutu482b6512017-07-11 10:13:23 -0700190 opencensus_api: 'io.opencensus:opencensus-api:0.5.1',
Yang Song4a0cf0b2017-06-06 18:16:55 -0700191 instrumentation_api: 'com.google.instrumentation:instrumentation-api:0.4.3',
Kun Zhangc5b94c72015-05-06 16:44:55 -0700192 protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
Eric Andersona8700a72016-07-29 11:57:41 -0700193 protobuf_lite: "com.google.protobuf:protobuf-lite:3.0.1",
Eric Andersonb1d72e52016-09-27 17:15:12 -0700194 protoc_lite: "com.google.protobuf:protoc-gen-javalite:3.0.0",
Kun Zhangbd23a8d2015-08-28 18:47:06 -0700195 protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${protobufNanoVersion}",
Carl Mastrangelod34260a2017-07-14 12:35:14 -0700196 protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.8.1',
Carl Mastrangelo8e1fba72016-03-02 09:30:35 -0800197 protobuf_util: "com.google.protobuf:protobuf-java-util:${protobufVersion}",
nathanmittler164b7342014-12-15 09:58:05 -0800198
Łukasz Strzałkowski67eefa62017-05-15 10:57:43 -0700199 netty: "io.netty:netty-codec-http2:[${nettyVersion}]",
200 netty_epoll: "io.netty:netty-transport-native-epoll:${nettyVersion}" + epoll_suffix,
201 netty_proxy_handler: "io.netty:netty-handler-proxy:${nettyVersion}",
Carl Mastrangeloe7fd6fc2017-06-26 18:29:14 -0700202 netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:2.0.5.Final',
nathanmittler164b7342014-12-15 09:58:05 -0800203
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800204 // Test dependencies.
205 junit: 'junit:junit:4.11',
Carl Mastrangelob3bc7fc2016-04-01 15:18:23 -0700206 mockito: 'org.mockito:mockito-core:1.9.5',
Louis Ryana7049bc2016-03-23 13:18:04 -0700207 truth: 'com.google.truth:truth:0.28',
208
209 // Benchmark dependencies
210 hdrhistogram: 'org.hdrhistogram:HdrHistogram:2.1.8',
211 math: 'org.apache.commons:commons-math3:3.6',
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700212
213 // Jetty ALPN dependencies
Eric Anderson308b6ea2017-03-13 10:13:42 -0700214 jetty_alpn_agent: 'org.mortbay.jetty.alpn:jetty-alpn-agent:2.0.6'
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800215 ]
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800216 }
nathanmittler164b7342014-12-15 09:58:05 -0800217
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700218 // Define a separate configuration for managing the dependency on Jetty ALPN agent.
nmittler74cfe6c2015-05-22 12:25:10 -0700219 configurations {
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700220 alpnagent
nmittler74cfe6c2015-05-22 12:25:10 -0700221 }
222
nathanmittler164b7342014-12-15 09:58:05 -0800223 dependencies {
224 testCompile libraries.junit,
225 libraries.mockito
nmittler74cfe6c2015-05-22 12:25:10 -0700226
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700227 // Configuration for modules that use Jetty ALPN agent
228 alpnagent libraries.jetty_alpn_agent
nathanmittler164b7342014-12-15 09:58:05 -0800229 }
Eric Anderson192144e2015-03-02 13:31:14 -0800230
231 signing {
232 required false
233 sign configurations.archives
234 }
235
nmittler732cfc02015-03-03 07:59:13 -0800236 // Disable JavaDoc doclint on Java 8. It's annoying.
237 if (JavaVersion.current().isJava8Compatible()) {
238 allprojects {
239 tasks.withType(Javadoc) {
240 options.addStringOption('Xdoclint:none', '-quiet')
241 }
242 }
243 }
244
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800245 checkstyle {
Eric Andersone6d00622017-07-07 10:57:03 -0700246 configFile = file("$rootDir/buildscripts/checkstyle.xml")
Eric Anderson6ab27ab2016-04-18 09:15:25 -0700247 toolVersion = "6.17"
Eric Andersonad44f0a2015-05-05 08:54:51 -0700248 ignoreFailures = false
Eric Anderson26141b42015-03-21 10:59:17 -0700249 if (rootProject.hasProperty("checkstyle.ignoreFailures")) {
250 ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean()
251 }
Eric Andersonefa774b2015-09-15 10:34:14 -0700252 configProperties["rootDir"] = rootDir
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800253 }
254
255 checkstyleMain {
Kun Zhang693a7d22015-05-06 11:35:08 -0700256 source = fileTree(dir: "src/main", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800257 }
258
259 checkstyleTest {
Kun Zhang693a7d22015-05-06 11:35:08 -0700260 source = fileTree(dir: "src/test", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800261 }
262
Eric Anderson192144e2015-03-02 13:31:14 -0800263 task javadocJar(type: Jar) {
264 classifier = 'javadoc'
265 from javadoc
266 }
267
268 task sourcesJar(type: Jar) {
269 classifier = 'sources'
270 from sourceSets.main.allSource
271 }
272
273 artifacts {
274 archives javadocJar, sourcesJar
275 }
276
277 uploadArchives.repositories.mavenDeployer {
278 beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
zhangkun83da3c3f82015-03-11 18:03:31 -0700279 String stagingUrl
Kun Zhang2f749712015-05-06 13:10:28 -0700280 if (rootProject.hasProperty('repositoryId')) {
281 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
282 rootProject.repositoryId
zhangkun83da3c3f82015-03-11 18:03:31 -0700283 } else {
284 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
285 }
Kun Zhang2f749712015-05-06 13:10:28 -0700286 def configureAuth = {
287 if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
288 authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
289 }
Eric Anderson192144e2015-03-02 13:31:14 -0800290 }
Kun Zhang2f749712015-05-06 13:10:28 -0700291 repository(url: stagingUrl, configureAuth)
292 snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
Eric Anderson192144e2015-03-02 13:31:14 -0800293 }
Carl Mastrangelo4988d8b2017-01-19 12:48:55 -0800294 uploadArchives.onlyIf { !name.contains("thrift") }
Eric Anderson192144e2015-03-02 13:31:14 -0800295
296 [
297 install.repositories.mavenInstaller,
298 uploadArchives.repositories.mavenDeployer,
299 ]*.pom*.whenConfigured { pom ->
300 pom.project {
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700301 name "$project.group:$project.name"
Eric Anderson192144e2015-03-02 13:31:14 -0800302 description project.description
303 url 'https://github.com/grpc/grpc-java'
304
305 scm {
Eric Andersonb7354952016-04-08 08:37:07 -0700306 connection 'scm:git:https://github.com/grpc/grpc-java.git'
307 developerConnection 'scm:git:git@github.com:grpc/grpc-java.git'
Eric Anderson192144e2015-03-02 13:31:14 -0800308 url 'https://github.com/grpc/grpc-java'
309 }
310
311 licenses {
312 license {
Carl Mastrangelo7b97df02017-05-31 14:37:42 -0700313 name 'Apache 2.0'
314 url 'https://opensource.org/licenses/Apache-2.0'
Eric Anderson192144e2015-03-02 13:31:14 -0800315 }
316 }
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700317
318 developers {
319 developer {
320 id "grpc.io"
321 name "gRPC Contributors"
322 email "grpc-io@googlegroups.com"
Mehrdad Afshari8ce0bc22017-07-10 22:48:17 +0000323 url "https://grpc.io/"
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700324 // https://issues.gradle.org/browse/GRADLE-2719
Carl Mastrangelo3bfd6302017-05-31 13:29:01 -0700325 organization = "gRPC Authors"
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700326 organizationUrl "https://www.google.com"
327 }
328 }
Eric Anderson192144e2015-03-02 13:31:14 -0800329 }
Eric Anderson90db93b2016-04-08 13:47:30 -0700330 if (!(project.name in
Naveen Reddy Chedeti28609592016-07-28 08:48:27 -0700331 ["grpc-stub", "grpc-protobuf", "grpc-protobuf-lite", "grpc-protobuf-nano", "grpc-thrift"])) {
Eric Anderson90db93b2016-04-08 13:47:30 -0700332 def core = pom.dependencies.find {dep -> dep.artifactId == 'grpc-core'}
333 if (core != null) {
334 // Depend on specific version of grpc-core because internal package is unstable
335 core.version = "[" + core.version + "]"
336 }
337 }
Eric Anderson192144e2015-03-02 13:31:14 -0800338 }
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700339 // At a test failure, log the stack trace to the console so that we don't
340 // have to open the HTML in a browser.
341 test {
342 testLogging {
343 exceptionFormat = 'full'
nmittler4ee2a652015-06-01 16:20:08 -0700344 showExceptions true
345 showCauses true
346 showStackTraces true
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700347 }
Eric Anderson56dca032016-02-12 08:48:41 -0800348 maxHeapSize = '1500m'
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700349 }
nathanmittler164b7342014-12-15 09:58:05 -0800350}