blob: 50f9de318c32c4042f882874cea441238942b526 [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'
Kun Zhang4bc2d6d2015-04-17 10:49:11 -07008 }
9}
Eric Andersonb938ba52015-02-28 09:59:25 -080010
Louis Ryan540b4d32015-09-04 13:26:24 -070011subprojects {
Eric Andersonc3e8dae2015-01-30 14:58:07 -080012 apply plugin: "checkstyle"
nathanmittler164b7342014-12-15 09:58:05 -080013 apply plugin: "java"
14 apply plugin: "maven"
nmittler52f42202015-01-21 14:30:14 -080015 apply plugin: "idea"
Eric Anderson192144e2015-03-02 13:31:14 -080016 apply plugin: "signing"
Eric Anderson041cdb12015-05-05 12:29:26 -070017 apply plugin: "jacoco"
nathanmittler164b7342014-12-15 09:58:05 -080018
nmittlerc4bcf142015-09-16 15:15:10 -070019 apply plugin: "com.google.osdetector"
nmittlerc4bcf142015-09-16 15:15:10 -070020
nmittlerf8314582015-01-27 10:25:39 -080021 group = "io.grpc"
Carl Mastrangelo3c5b5a52016-04-29 13:37:20 -070022 version = "0.15.0-SNAPSHOT" // CURRENT_GRPC_VERSION
nathanmittler164b7342014-12-15 09:58:05 -080023
24 sourceCompatibility = 1.6
25 targetCompatibility = 1.6
26
27 repositories {
28 mavenCentral()
29 mavenLocal()
30 }
31
Eric Anderson76d09552015-03-12 15:25:11 -070032 [compileJava, compileTestJava].each() {
Eric Anderson641cb352016-05-24 14:29:52 -070033 it.options.compilerArgs += ["-Xlint:all", "-Xlint:-options"]
Eric Anderson76d09552015-03-12 15:25:11 -070034 it.options.encoding = "UTF-8"
nmittler02c953e2015-01-26 14:03:11 -080035 }
36
Eric Anderson641cb352016-05-24 14:29:52 -070037 compileTestJava {
38 // serialVersionUID is basically guaranteed to be useless in our tests
39 options.compilerArgs += ["-Xlint:-serial"]
40 }
41
nmittler8c1d38a2015-06-01 08:31:00 -070042 jar.manifest {
43 attributes('Implementation-Title': name,
44 'Implementation-Version': version,
45 'Built-By': System.getProperty('user.name'),
46 'Built-JDK': System.getProperty('java.version'),
47 'Source-Compatibility': sourceCompatibility,
48 'Target-Compatibility': targetCompatibility)
49 }
50
Eric Anderson10fb2062015-05-05 10:28:38 -070051 javadoc.options {
52 encoding = 'UTF-8'
53 links 'https://docs.oracle.com/javase/8/docs/api/'
54 }
Eric Anderson14444a92015-03-11 16:44:38 -070055
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -080056 ext {
Kun Zhang6b1e7d62015-05-07 15:20:44 -070057 def exeSuffix = osdetector.os == 'windows' ? ".exe" : ""
58 protocPluginBaseName = 'protoc-gen-grpc-java'
Eric Anderson46ce4092016-01-26 12:13:06 -080059 javaPluginPath = "$rootDir/compiler/build/exe/java_plugin/$protocPluginBaseName$exeSuffix"
Kun Zhang6b1e7d62015-05-07 15:20:44 -070060
Carl Mastrangelo28253612016-05-16 10:23:53 -070061 guavaVersion = '19.0'
Kun Zhange2ed2e82016-01-27 08:26:19 -080062 protobufVersion = '3.0.0-beta-2'
63 protobufNanoVersion = '3.0.0-alpha-5'
Kun Zhang6b1e7d62015-05-07 15:20:44 -070064
Kun Zhang111f6dd2015-05-05 16:11:27 -070065 configureProtoCompilation = {
Kun Zhang35f77ee2015-06-22 16:29:30 -070066 String generatedSourcePath = "${projectDir}/src/generated"
Kun Zhang111f6dd2015-05-05 16:11:27 -070067 if (rootProject.childProjects.containsKey('grpc-compiler')) {
68 // Only when the codegen is built along with the project, will we be able to recompile
69 // the proto files.
70 project.apply plugin: 'com.google.protobuf'
Kun Zhang35f77ee2015-06-22 16:29:30 -070071 project.protobuf {
72 protoc {
73 if (project.hasProperty('protoc')) {
74 path = project.protoc
75 } else {
76 artifact = "com.google.protobuf:protoc:${protobufVersion}"
77 }
78 }
79 plugins {
80 grpc {
81 path = javaPluginPath
82 }
83 }
84 generateProtoTasks {
85 all().each { task ->
86 task.dependsOn ':grpc-compiler:java_pluginExecutable'
87 // Delete the generated sources first, so that we can be alerted if they are not re-compiled.
Eric Andersone9b4d152016-04-19 11:54:04 -070088 task.dependsOn 'deleteGeneratedSource' + task.sourceSet.name
Kun Zhang35f77ee2015-06-22 16:29:30 -070089 // Recompile protos when the codegen has been changed
90 task.inputs.file javaPluginPath
91 // Recompile protos when build.gradle has been changed, because
92 // it's possible the version of protoc has been changed.
93 task.inputs.file "${rootProject.projectDir}/build.gradle"
94 task.plugins {
95 grpc {}
Kun Zhang2cdc5e32015-05-11 16:58:28 -070096 }
97 }
98 }
Kun Zhang35f77ee2015-06-22 16:29:30 -070099 generatedFilesBaseDir = generatedSourcePath
100 }
101
Eric Andersone9b4d152016-04-19 11:54:04 -0700102 sourceSets.each { sourceSet ->
103 task "deleteGeneratedSource${sourceSet.name}" << {
104 project.delete project.fileTree(dir: generatedSourcePath + '/' + sourceSet.name)
105 }
Kun Zhang2cdc5e32015-05-11 16:58:28 -0700106 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700107 } else {
108 // Otherwise, we just use the checked-in generated code.
109 project.sourceSets {
110 main {
111 java {
Kun Zhang35f77ee2015-06-22 16:29:30 -0700112 srcDir "${generatedSourcePath}/main/java"
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700113 srcDir "${generatedSourcePath}/main/javanano"
Kun Zhang35f77ee2015-06-22 16:29:30 -0700114 srcDir "${generatedSourcePath}/main/grpc"
Kun Zhang287a27a2015-05-07 17:32:31 -0700115 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700116 }
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700117 test {
118 java {
119 srcDir "${generatedSourcePath}/test/java"
120 srcDir "${generatedSourcePath}/test/javanano"
121 srcDir "${generatedSourcePath}/test/grpc"
122 }
123 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700124 }
125 }
126 }
127
Eric Anderson65d73c02015-05-21 11:54:04 -0700128 def epoll_suffix = "";
129 if (osdetector.classifier in ["linux-x86_64"]) {
130 // The native code is only pre-compiled on certain platforms.
131 epoll_suffix = ":" + osdetector.classifier
132 }
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800133 libraries = [
Carl Mastrangelo28253612016-05-16 10:23:53 -0700134 guava: "com.google.guava:guava:${guavaVersion}",
Jeff Pinnerb1cc7cc2015-02-25 10:17:23 -0800135 hpack: 'com.twitter:hpack:0.10.1',
nmittlerb897a892015-02-23 12:03:59 -0800136 jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
Eric Andersond52a7a22015-09-03 16:44:48 -0700137 oauth_client: 'com.google.auth:google-auth-library-oauth2-http:0.3.0',
Xudong Ma6d296e82015-09-21 10:39:00 -0700138 okhttp: 'com.squareup.okhttp:okhttp:2.5.0',
Xudong Mab121c462015-09-21 12:54:06 -0700139 okio: 'com.squareup.okio:okio:1.6.0',
Kun Zhangc5b94c72015-05-06 16:44:55 -0700140 protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
Kun Zhangbd23a8d2015-08-28 18:47:06 -0700141 protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${protobufNanoVersion}",
Eric Anderson446f0cb2016-05-07 11:24:15 -0700142 protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.7.7',
Carl Mastrangelo8e1fba72016-03-02 09:30:35 -0800143 protobuf_util: "com.google.protobuf:protobuf-java-util:${protobufVersion}",
nathanmittler164b7342014-12-15 09:58:05 -0800144
Eric Anderson511bea02016-04-11 18:49:58 -0700145 netty: 'io.netty:netty-codec-http2:[4.1.0.CR7]',
146 netty_epoll: 'io.netty:netty-transport-native-epoll:4.1.0.CR7' + epoll_suffix,
buchgr88d31742016-03-23 22:58:23 +0100147 netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork15:' + osdetector.classifier,
nathanmittler164b7342014-12-15 09:58:05 -0800148
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800149 // Test dependencies.
150 junit: 'junit:junit:4.11',
Carl Mastrangelob3bc7fc2016-04-01 15:18:23 -0700151 mockito: 'org.mockito:mockito-core:1.9.5',
Louis Ryana7049bc2016-03-23 13:18:04 -0700152 truth: 'com.google.truth:truth:0.28',
153
154 // Benchmark dependencies
155 hdrhistogram: 'org.hdrhistogram:HdrHistogram:2.1.8',
156 math: 'org.apache.commons:commons-math3:3.6',
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700157
158 // Jetty ALPN dependencies
Eric Andersonaa92d6c2016-05-19 11:41:03 -0700159 jetty_alpn_agent: 'org.mortbay.jetty.alpn:jetty-alpn-agent:2.0.3'
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800160 ]
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800161 }
nathanmittler164b7342014-12-15 09:58:05 -0800162
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700163 // Define a separate configuration for managing the dependency on Jetty ALPN agent.
nmittler74cfe6c2015-05-22 12:25:10 -0700164 configurations {
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700165 alpnagent
nmittler9466eb52015-09-04 15:13:46 -0700166 tcnative
nmittler74cfe6c2015-05-22 12:25:10 -0700167 }
168
nathanmittler164b7342014-12-15 09:58:05 -0800169 dependencies {
170 testCompile libraries.junit,
171 libraries.mockito
nmittler74cfe6c2015-05-22 12:25:10 -0700172
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700173 // Configuration for modules that use Jetty ALPN agent
174 alpnagent libraries.jetty_alpn_agent
nmittler9466eb52015-09-04 15:13:46 -0700175
176 // Configuration for modules that use Netty tcnative (for OpenSSL).
177 tcnative libraries.netty_tcnative
nathanmittler164b7342014-12-15 09:58:05 -0800178 }
Eric Anderson192144e2015-03-02 13:31:14 -0800179
180 signing {
181 required false
182 sign configurations.archives
183 }
184
nmittler732cfc02015-03-03 07:59:13 -0800185 // Disable JavaDoc doclint on Java 8. It's annoying.
186 if (JavaVersion.current().isJava8Compatible()) {
187 allprojects {
188 tasks.withType(Javadoc) {
189 options.addStringOption('Xdoclint:none', '-quiet')
190 }
191 }
192 }
193
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800194 checkstyle {
195 configFile = file("$rootDir/checkstyle.xml")
Eric Anderson6ab27ab2016-04-18 09:15:25 -0700196 toolVersion = "6.17"
Eric Andersonad44f0a2015-05-05 08:54:51 -0700197 ignoreFailures = false
Eric Anderson26141b42015-03-21 10:59:17 -0700198 if (rootProject.hasProperty("checkstyle.ignoreFailures")) {
199 ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean()
200 }
Eric Andersonefa774b2015-09-15 10:34:14 -0700201 configProperties["rootDir"] = rootDir
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800202 }
203
204 checkstyleMain {
Kun Zhang693a7d22015-05-06 11:35:08 -0700205 source = fileTree(dir: "src/main", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800206 }
207
208 checkstyleTest {
Kun Zhang693a7d22015-05-06 11:35:08 -0700209 source = fileTree(dir: "src/test", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800210 }
211
Eric Anderson192144e2015-03-02 13:31:14 -0800212 task javadocJar(type: Jar) {
213 classifier = 'javadoc'
214 from javadoc
215 }
216
217 task sourcesJar(type: Jar) {
218 classifier = 'sources'
219 from sourceSets.main.allSource
220 }
221
222 artifacts {
223 archives javadocJar, sourcesJar
224 }
225
226 uploadArchives.repositories.mavenDeployer {
227 beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
zhangkun83da3c3f82015-03-11 18:03:31 -0700228 String stagingUrl
Kun Zhang2f749712015-05-06 13:10:28 -0700229 if (rootProject.hasProperty('repositoryId')) {
230 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
231 rootProject.repositoryId
zhangkun83da3c3f82015-03-11 18:03:31 -0700232 } else {
233 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
234 }
Kun Zhang2f749712015-05-06 13:10:28 -0700235 def configureAuth = {
236 if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
237 authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
238 }
Eric Anderson192144e2015-03-02 13:31:14 -0800239 }
Kun Zhang2f749712015-05-06 13:10:28 -0700240 repository(url: stagingUrl, configureAuth)
241 snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
Eric Anderson192144e2015-03-02 13:31:14 -0800242 }
243
244 [
245 install.repositories.mavenInstaller,
246 uploadArchives.repositories.mavenDeployer,
247 ]*.pom*.whenConfigured { pom ->
248 pom.project {
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700249 name "$project.group:$project.name"
Eric Anderson192144e2015-03-02 13:31:14 -0800250 description project.description
251 url 'https://github.com/grpc/grpc-java'
252
253 scm {
Eric Andersonb7354952016-04-08 08:37:07 -0700254 connection 'scm:git:https://github.com/grpc/grpc-java.git'
255 developerConnection 'scm:git:git@github.com:grpc/grpc-java.git'
Eric Anderson192144e2015-03-02 13:31:14 -0800256 url 'https://github.com/grpc/grpc-java'
257 }
258
259 licenses {
260 license {
261 name 'BSD 3-Clause'
262 url 'http://opensource.org/licenses/BSD-3-Clause'
263 }
264 }
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700265
266 developers {
267 developer {
268 id "grpc.io"
269 name "gRPC Contributors"
270 email "grpc-io@googlegroups.com"
271 url "http://grpc.io/"
272 // https://issues.gradle.org/browse/GRADLE-2719
273 organization = "Google, Inc."
274 organizationUrl "https://www.google.com"
275 }
276 }
Eric Anderson192144e2015-03-02 13:31:14 -0800277 }
Eric Anderson90db93b2016-04-08 13:47:30 -0700278 if (!(project.name in
279 ["grpc-stub", "grpc-protobuf", "grpc-protobuf-lite", "grpc-protobuf-nano"])) {
280 def core = pom.dependencies.find {dep -> dep.artifactId == 'grpc-core'}
281 if (core != null) {
282 // Depend on specific version of grpc-core because internal package is unstable
283 core.version = "[" + core.version + "]"
284 }
285 }
Eric Anderson192144e2015-03-02 13:31:14 -0800286 }
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700287 // At a test failure, log the stack trace to the console so that we don't
288 // have to open the HTML in a browser.
289 test {
290 testLogging {
291 exceptionFormat = 'full'
nmittler4ee2a652015-06-01 16:20:08 -0700292 showExceptions true
293 showCauses true
294 showStackTraces true
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700295 }
Eric Anderson56dca032016-02-12 08:48:41 -0800296 maxHeapSize = '1500m'
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700297 }
nathanmittler164b7342014-12-15 09:58:05 -0800298}