blob: def381d746e647e857ff3be19247c4cf7261da2e [file] [log] [blame]
Kun Zhang4bc2d6d2015-04-17 10:49:11 -07001buildscript {
2 repositories {
3 mavenCentral()
4 mavenLocal()
5 }
6 dependencies {
nmittlerc4bcf142015-09-16 15:15:10 -07007 classpath 'com.google.gradle:osdetector-gradle-plugin:1.4.0'
Eric Anderson42aa64c2017-02-02 13:48:12 -08008 classpath "ru.vyarus:gradle-animalsniffer-plugin:1.2.0"
Kun Zhang4bc2d6d2015-04-17 10:49:11 -07009 }
10}
Eric Andersonb938ba52015-02-28 09:59:25 -080011
Louis Ryan540b4d32015-09-04 13:26:24 -070012subprojects {
Eric Andersonc3e8dae2015-01-30 14:58:07 -080013 apply plugin: "checkstyle"
nathanmittler164b7342014-12-15 09:58:05 -080014 apply plugin: "java"
15 apply plugin: "maven"
nmittler52f42202015-01-21 14:30:14 -080016 apply plugin: "idea"
Eric Anderson192144e2015-03-02 13:31:14 -080017 apply plugin: "signing"
Eric Anderson041cdb12015-05-05 12:29:26 -070018 apply plugin: "jacoco"
nathanmittler164b7342014-12-15 09:58:05 -080019
nmittlerc4bcf142015-09-16 15:15:10 -070020 apply plugin: "com.google.osdetector"
Eric Anderson42aa64c2017-02-02 13:48:12 -080021 // The plugin only has an effect if a signature is specified
22 apply plugin: "ru.vyarus.animalsniffer"
nmittlerc4bcf142015-09-16 15:15:10 -070023
nmittlerf8314582015-01-27 10:25:39 -080024 group = "io.grpc"
Carl Mastrangeloe8aef5b2017-01-30 16:40:12 -080025 version = "1.2.0-SNAPSHOT" // CURRENT_GRPC_VERSION
nathanmittler164b7342014-12-15 09:58:05 -080026
27 sourceCompatibility = 1.6
28 targetCompatibility = 1.6
29
30 repositories {
31 mavenCentral()
32 mavenLocal()
33 }
34
Eric Anderson76d09552015-03-12 15:25:11 -070035 [compileJava, compileTestJava].each() {
Eric Anderson641cb352016-05-24 14:29:52 -070036 it.options.compilerArgs += ["-Xlint:all", "-Xlint:-options"]
Eric Anderson76d09552015-03-12 15:25:11 -070037 it.options.encoding = "UTF-8"
Eric Anderson3c03eb72016-07-10 11:40:12 -070038 if (rootProject.hasProperty('failOnWarnings') && rootProject.failOnWarnings.toBoolean()) {
39 it.options.compilerArgs += ["-Werror"]
40 }
nmittler02c953e2015-01-26 14:03:11 -080041 }
42
Eric Anderson641cb352016-05-24 14:29:52 -070043 compileTestJava {
44 // serialVersionUID is basically guaranteed to be useless in our tests
45 options.compilerArgs += ["-Xlint:-serial"]
46 }
47
nmittler8c1d38a2015-06-01 08:31:00 -070048 jar.manifest {
49 attributes('Implementation-Title': name,
50 'Implementation-Version': version,
51 'Built-By': System.getProperty('user.name'),
52 'Built-JDK': System.getProperty('java.version'),
53 'Source-Compatibility': sourceCompatibility,
54 'Target-Compatibility': targetCompatibility)
55 }
56
Eric Anderson10fb2062015-05-05 10:28:38 -070057 javadoc.options {
58 encoding = 'UTF-8'
59 links 'https://docs.oracle.com/javase/8/docs/api/'
60 }
Eric Anderson14444a92015-03-11 16:44:38 -070061
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -080062 ext {
Kun Zhang6b1e7d62015-05-07 15:20:44 -070063 def exeSuffix = osdetector.os == 'windows' ? ".exe" : ""
64 protocPluginBaseName = 'protoc-gen-grpc-java'
Eric Anderson46ce4092016-01-26 12:13:06 -080065 javaPluginPath = "$rootDir/compiler/build/exe/java_plugin/$protocPluginBaseName$exeSuffix"
Kun Zhang6b1e7d62015-05-07 15:20:44 -070066
Carl Mastrangeloce9d1522016-12-16 15:15:17 -080067 guavaVersion = '20.0'
Carl Mastrangelob0323ac2017-02-07 09:47:15 -080068 protobufVersion = '3.2.0'
Kun Zhange2ed2e82016-01-27 08:26:19 -080069 protobufNanoVersion = '3.0.0-alpha-5'
Kun Zhang6b1e7d62015-05-07 15:20:44 -070070
Kun Zhang111f6dd2015-05-05 16:11:27 -070071 configureProtoCompilation = {
Kun Zhang35f77ee2015-06-22 16:29:30 -070072 String generatedSourcePath = "${projectDir}/src/generated"
Kun Zhang111f6dd2015-05-05 16:11:27 -070073 if (rootProject.childProjects.containsKey('grpc-compiler')) {
74 // Only when the codegen is built along with the project, will we be able to recompile
75 // the proto files.
76 project.apply plugin: 'com.google.protobuf'
Kun Zhang35f77ee2015-06-22 16:29:30 -070077 project.protobuf {
78 protoc {
79 if (project.hasProperty('protoc')) {
80 path = project.protoc
81 } else {
82 artifact = "com.google.protobuf:protoc:${protobufVersion}"
83 }
84 }
85 plugins {
86 grpc {
87 path = javaPluginPath
88 }
89 }
90 generateProtoTasks {
91 all().each { task ->
92 task.dependsOn ':grpc-compiler:java_pluginExecutable'
93 // Delete the generated sources first, so that we can be alerted if they are not re-compiled.
Eric Andersone9b4d152016-04-19 11:54:04 -070094 task.dependsOn 'deleteGeneratedSource' + task.sourceSet.name
Kun Zhang35f77ee2015-06-22 16:29:30 -070095 // Recompile protos when the codegen has been changed
96 task.inputs.file javaPluginPath
97 // Recompile protos when build.gradle has been changed, because
98 // it's possible the version of protoc has been changed.
99 task.inputs.file "${rootProject.projectDir}/build.gradle"
100 task.plugins {
ZHANG Dapenge1091252016-07-21 16:35:18 -0700101 grpc {
102 // To generate deprecated interfaces and static bindService method,
103 // turn the enable_deprecated option to true below:
104 option 'enable_deprecated=false'
105 }
Kun Zhang2cdc5e32015-05-11 16:58:28 -0700106 }
107 }
108 }
Kun Zhang35f77ee2015-06-22 16:29:30 -0700109 generatedFilesBaseDir = generatedSourcePath
110 }
111
Eric Andersone9b4d152016-04-19 11:54:04 -0700112 sourceSets.each { sourceSet ->
113 task "deleteGeneratedSource${sourceSet.name}" << {
114 project.delete project.fileTree(dir: generatedSourcePath + '/' + sourceSet.name)
115 }
Kun Zhang2cdc5e32015-05-11 16:58:28 -0700116 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700117 } else {
118 // Otherwise, we just use the checked-in generated code.
119 project.sourceSets {
120 main {
121 java {
Kun Zhang35f77ee2015-06-22 16:29:30 -0700122 srcDir "${generatedSourcePath}/main/java"
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700123 srcDir "${generatedSourcePath}/main/javanano"
Kun Zhang35f77ee2015-06-22 16:29:30 -0700124 srcDir "${generatedSourcePath}/main/grpc"
Kun Zhang287a27a2015-05-07 17:32:31 -0700125 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700126 }
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700127 test {
128 java {
129 srcDir "${generatedSourcePath}/test/java"
130 srcDir "${generatedSourcePath}/test/javanano"
131 srcDir "${generatedSourcePath}/test/grpc"
132 }
133 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700134 }
135 }
Eric Andersondbef1af2016-05-23 12:05:41 -0700136
Eric Gribkoffc8c9fff2016-11-28 13:20:55 -0800137 [compileJava, compileTestJava].each() {
Eric Andersondbef1af2016-05-23 12:05:41 -0700138 // Protobuf-generated code produces some warnings.
Eric Gribkoffc8c9fff2016-11-28 13:20:55 -0800139 it.options.compilerArgs += ["-Xlint:-cast"]
Eric Andersondbef1af2016-05-23 12:05:41 -0700140 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700141 }
142
Eric Anderson65d73c02015-05-21 11:54:04 -0700143 def epoll_suffix = "";
144 if (osdetector.classifier in ["linux-x86_64"]) {
145 // The native code is only pre-compiled on certain platforms.
146 epoll_suffix = ":" + osdetector.classifier
147 }
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800148 libraries = [
Carl Mastrangelo26a08cd2016-08-18 18:57:50 -0700149 errorprone: "com.google.errorprone:error_prone_annotations:2.0.11",
Carl Mastrangelo28253612016-05-16 10:23:53 -0700150 guava: "com.google.guava:guava:${guavaVersion}",
Jeff Pinnerb1cc7cc2015-02-25 10:17:23 -0800151 hpack: 'com.twitter:hpack:0.10.1',
nmittlerb897a892015-02-23 12:03:59 -0800152 jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
Kun Zhangdef237d2016-06-14 13:51:24 -0700153 oauth_client: 'com.google.auth:google-auth-library-oauth2-http:0.4.0',
154 google_auth_credentials: 'com.google.auth:google-auth-library-credentials:0.4.0',
Xudong Ma6d296e82015-09-21 10:39:00 -0700155 okhttp: 'com.squareup.okhttp:okhttp:2.5.0',
Xudong Mab121c462015-09-21 12:54:06 -0700156 okio: 'com.squareup.okio:okio:1.6.0',
Kun Zhangcce8eac2017-01-05 10:48:13 -0800157 instrumentation_api: 'com.google.instrumentation:instrumentation-api:0.3.0',
Kun Zhangc5b94c72015-05-06 16:44:55 -0700158 protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
Eric Andersona8700a72016-07-29 11:57:41 -0700159 // swap to ${protobufVersion} after versions align again
160 protobuf_lite: "com.google.protobuf:protobuf-lite:3.0.1",
Eric Andersonb1d72e52016-09-27 17:15:12 -0700161 // swap to ${protobufVersion} after versions align again
162 protoc_lite: "com.google.protobuf:protoc-gen-javalite:3.0.0",
Kun Zhangbd23a8d2015-08-28 18:47:06 -0700163 protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${protobufNanoVersion}",
Kun Zhang9d747bb2016-08-18 13:06:18 -0700164 protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.8.0',
Carl Mastrangelo8e1fba72016-03-02 09:30:35 -0800165 protobuf_util: "com.google.protobuf:protobuf-java-util:${protobufVersion}",
nathanmittler164b7342014-12-15 09:58:05 -0800166
Carl Mastrangelo0c0ce372017-01-30 12:40:46 -0800167 netty: 'io.netty:netty-codec-http2:[4.1.8.Final]',
168 netty_epoll: 'io.netty:netty-transport-native-epoll:4.1.8.Final' + epoll_suffix,
169 netty_proxy_handler: 'io.netty:netty-handler-proxy:4.1.8.Final',
170 netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork26',
nathanmittler164b7342014-12-15 09:58:05 -0800171
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800172 // Test dependencies.
173 junit: 'junit:junit:4.11',
Carl Mastrangelob3bc7fc2016-04-01 15:18:23 -0700174 mockito: 'org.mockito:mockito-core:1.9.5',
Louis Ryana7049bc2016-03-23 13:18:04 -0700175 truth: 'com.google.truth:truth:0.28',
176
177 // Benchmark dependencies
178 hdrhistogram: 'org.hdrhistogram:HdrHistogram:2.1.8',
179 math: 'org.apache.commons:commons-math3:3.6',
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700180
181 // Jetty ALPN dependencies
Eric Andersonaa92d6c2016-05-19 11:41:03 -0700182 jetty_alpn_agent: 'org.mortbay.jetty.alpn:jetty-alpn-agent:2.0.3'
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800183 ]
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800184 }
nathanmittler164b7342014-12-15 09:58:05 -0800185
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700186 // Define a separate configuration for managing the dependency on Jetty ALPN agent.
nmittler74cfe6c2015-05-22 12:25:10 -0700187 configurations {
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700188 alpnagent
nmittler9466eb52015-09-04 15:13:46 -0700189 tcnative
nmittler74cfe6c2015-05-22 12:25:10 -0700190 }
191
nathanmittler164b7342014-12-15 09:58:05 -0800192 dependencies {
193 testCompile libraries.junit,
194 libraries.mockito
nmittler74cfe6c2015-05-22 12:25:10 -0700195
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700196 // Configuration for modules that use Jetty ALPN agent
197 alpnagent libraries.jetty_alpn_agent
nmittler9466eb52015-09-04 15:13:46 -0700198
199 // Configuration for modules that use Netty tcnative (for OpenSSL).
200 tcnative libraries.netty_tcnative
nathanmittler164b7342014-12-15 09:58:05 -0800201 }
Eric Anderson192144e2015-03-02 13:31:14 -0800202
203 signing {
204 required false
205 sign configurations.archives
206 }
207
nmittler732cfc02015-03-03 07:59:13 -0800208 // Disable JavaDoc doclint on Java 8. It's annoying.
209 if (JavaVersion.current().isJava8Compatible()) {
210 allprojects {
211 tasks.withType(Javadoc) {
212 options.addStringOption('Xdoclint:none', '-quiet')
213 }
214 }
215 }
216
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800217 checkstyle {
218 configFile = file("$rootDir/checkstyle.xml")
Eric Anderson6ab27ab2016-04-18 09:15:25 -0700219 toolVersion = "6.17"
Eric Andersonad44f0a2015-05-05 08:54:51 -0700220 ignoreFailures = false
Eric Anderson26141b42015-03-21 10:59:17 -0700221 if (rootProject.hasProperty("checkstyle.ignoreFailures")) {
222 ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean()
223 }
Eric Andersonefa774b2015-09-15 10:34:14 -0700224 configProperties["rootDir"] = rootDir
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800225 }
226
227 checkstyleMain {
Kun Zhang693a7d22015-05-06 11:35:08 -0700228 source = fileTree(dir: "src/main", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800229 }
230
231 checkstyleTest {
Kun Zhang693a7d22015-05-06 11:35:08 -0700232 source = fileTree(dir: "src/test", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800233 }
234
Eric Anderson192144e2015-03-02 13:31:14 -0800235 task javadocJar(type: Jar) {
236 classifier = 'javadoc'
237 from javadoc
238 }
239
240 task sourcesJar(type: Jar) {
241 classifier = 'sources'
242 from sourceSets.main.allSource
243 }
244
245 artifacts {
246 archives javadocJar, sourcesJar
247 }
248
249 uploadArchives.repositories.mavenDeployer {
250 beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
zhangkun83da3c3f82015-03-11 18:03:31 -0700251 String stagingUrl
Kun Zhang2f749712015-05-06 13:10:28 -0700252 if (rootProject.hasProperty('repositoryId')) {
253 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
254 rootProject.repositoryId
zhangkun83da3c3f82015-03-11 18:03:31 -0700255 } else {
256 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
257 }
Kun Zhang2f749712015-05-06 13:10:28 -0700258 def configureAuth = {
259 if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
260 authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
261 }
Eric Anderson192144e2015-03-02 13:31:14 -0800262 }
Kun Zhang2f749712015-05-06 13:10:28 -0700263 repository(url: stagingUrl, configureAuth)
264 snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
Eric Anderson192144e2015-03-02 13:31:14 -0800265 }
Carl Mastrangelo4988d8b2017-01-19 12:48:55 -0800266 uploadArchives.onlyIf { !name.contains("thrift") }
Eric Anderson192144e2015-03-02 13:31:14 -0800267
268 [
269 install.repositories.mavenInstaller,
270 uploadArchives.repositories.mavenDeployer,
271 ]*.pom*.whenConfigured { pom ->
272 pom.project {
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700273 name "$project.group:$project.name"
Eric Anderson192144e2015-03-02 13:31:14 -0800274 description project.description
275 url 'https://github.com/grpc/grpc-java'
276
277 scm {
Eric Andersonb7354952016-04-08 08:37:07 -0700278 connection 'scm:git:https://github.com/grpc/grpc-java.git'
279 developerConnection 'scm:git:git@github.com:grpc/grpc-java.git'
Eric Anderson192144e2015-03-02 13:31:14 -0800280 url 'https://github.com/grpc/grpc-java'
281 }
282
283 licenses {
284 license {
285 name 'BSD 3-Clause'
286 url 'http://opensource.org/licenses/BSD-3-Clause'
287 }
288 }
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700289
290 developers {
291 developer {
292 id "grpc.io"
293 name "gRPC Contributors"
294 email "grpc-io@googlegroups.com"
295 url "http://grpc.io/"
296 // https://issues.gradle.org/browse/GRADLE-2719
297 organization = "Google, Inc."
298 organizationUrl "https://www.google.com"
299 }
300 }
Eric Anderson192144e2015-03-02 13:31:14 -0800301 }
Eric Anderson90db93b2016-04-08 13:47:30 -0700302 if (!(project.name in
Naveen Reddy Chedeti28609592016-07-28 08:48:27 -0700303 ["grpc-stub", "grpc-protobuf", "grpc-protobuf-lite", "grpc-protobuf-nano", "grpc-thrift"])) {
Eric Anderson90db93b2016-04-08 13:47:30 -0700304 def core = pom.dependencies.find {dep -> dep.artifactId == 'grpc-core'}
305 if (core != null) {
306 // Depend on specific version of grpc-core because internal package is unstable
307 core.version = "[" + core.version + "]"
308 }
309 }
Eric Anderson192144e2015-03-02 13:31:14 -0800310 }
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700311 // At a test failure, log the stack trace to the console so that we don't
312 // have to open the HTML in a browser.
313 test {
314 testLogging {
315 exceptionFormat = 'full'
nmittler4ee2a652015-06-01 16:20:08 -0700316 showExceptions true
317 showCauses true
318 showStackTraces true
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700319 }
Eric Anderson56dca032016-02-12 08:48:41 -0800320 maxHeapSize = '1500m'
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700321 }
nathanmittler164b7342014-12-15 09:58:05 -0800322}