blob: 717a09181b9d1d287bc0783a43b896c78083374d [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 Andersonec965ca2015-06-18 12:40:08 -070033 it.options.compilerArgs += ["-Xlint:unchecked", "-Xlint:deprecation", "-Xlint:-options",
34 "-Xlint:rawtypes"]
Eric Anderson76d09552015-03-12 15:25:11 -070035 it.options.encoding = "UTF-8"
nmittler02c953e2015-01-26 14:03:11 -080036 }
37
nmittler8c1d38a2015-06-01 08:31:00 -070038 jar.manifest {
39 attributes('Implementation-Title': name,
40 'Implementation-Version': version,
41 'Built-By': System.getProperty('user.name'),
42 'Built-JDK': System.getProperty('java.version'),
43 'Source-Compatibility': sourceCompatibility,
44 'Target-Compatibility': targetCompatibility)
45 }
46
Eric Anderson10fb2062015-05-05 10:28:38 -070047 javadoc.options {
48 encoding = 'UTF-8'
49 links 'https://docs.oracle.com/javase/8/docs/api/'
50 }
Eric Anderson14444a92015-03-11 16:44:38 -070051
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -080052 ext {
Kun Zhang6b1e7d62015-05-07 15:20:44 -070053 def exeSuffix = osdetector.os == 'windows' ? ".exe" : ""
54 protocPluginBaseName = 'protoc-gen-grpc-java'
Eric Anderson46ce4092016-01-26 12:13:06 -080055 javaPluginPath = "$rootDir/compiler/build/exe/java_plugin/$protocPluginBaseName$exeSuffix"
Kun Zhang6b1e7d62015-05-07 15:20:44 -070056
Carl Mastrangelo28253612016-05-16 10:23:53 -070057 guavaVersion = '19.0'
Kun Zhange2ed2e82016-01-27 08:26:19 -080058 protobufVersion = '3.0.0-beta-2'
59 protobufNanoVersion = '3.0.0-alpha-5'
Kun Zhang6b1e7d62015-05-07 15:20:44 -070060
Kun Zhang111f6dd2015-05-05 16:11:27 -070061 configureProtoCompilation = {
Kun Zhang35f77ee2015-06-22 16:29:30 -070062 String generatedSourcePath = "${projectDir}/src/generated"
Kun Zhang111f6dd2015-05-05 16:11:27 -070063 if (rootProject.childProjects.containsKey('grpc-compiler')) {
64 // Only when the codegen is built along with the project, will we be able to recompile
65 // the proto files.
66 project.apply plugin: 'com.google.protobuf'
Kun Zhang35f77ee2015-06-22 16:29:30 -070067 project.protobuf {
68 protoc {
69 if (project.hasProperty('protoc')) {
70 path = project.protoc
71 } else {
72 artifact = "com.google.protobuf:protoc:${protobufVersion}"
73 }
74 }
75 plugins {
76 grpc {
77 path = javaPluginPath
78 }
79 }
80 generateProtoTasks {
81 all().each { task ->
82 task.dependsOn ':grpc-compiler:java_pluginExecutable'
83 // Delete the generated sources first, so that we can be alerted if they are not re-compiled.
Eric Andersone9b4d152016-04-19 11:54:04 -070084 task.dependsOn 'deleteGeneratedSource' + task.sourceSet.name
Kun Zhang35f77ee2015-06-22 16:29:30 -070085 // Recompile protos when the codegen has been changed
86 task.inputs.file javaPluginPath
87 // Recompile protos when build.gradle has been changed, because
88 // it's possible the version of protoc has been changed.
89 task.inputs.file "${rootProject.projectDir}/build.gradle"
90 task.plugins {
91 grpc {}
Kun Zhang2cdc5e32015-05-11 16:58:28 -070092 }
93 }
94 }
Kun Zhang35f77ee2015-06-22 16:29:30 -070095 generatedFilesBaseDir = generatedSourcePath
96 }
97
Eric Andersone9b4d152016-04-19 11:54:04 -070098 sourceSets.each { sourceSet ->
99 task "deleteGeneratedSource${sourceSet.name}" << {
100 project.delete project.fileTree(dir: generatedSourcePath + '/' + sourceSet.name)
101 }
Kun Zhang2cdc5e32015-05-11 16:58:28 -0700102 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700103 } else {
104 // Otherwise, we just use the checked-in generated code.
105 project.sourceSets {
106 main {
107 java {
Kun Zhang35f77ee2015-06-22 16:29:30 -0700108 srcDir "${generatedSourcePath}/main/java"
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700109 srcDir "${generatedSourcePath}/main/javanano"
Kun Zhang35f77ee2015-06-22 16:29:30 -0700110 srcDir "${generatedSourcePath}/main/grpc"
Kun Zhang287a27a2015-05-07 17:32:31 -0700111 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700112 }
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700113 test {
114 java {
115 srcDir "${generatedSourcePath}/test/java"
116 srcDir "${generatedSourcePath}/test/javanano"
117 srcDir "${generatedSourcePath}/test/grpc"
118 }
119 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700120 }
121 }
122 }
123
Eric Anderson65d73c02015-05-21 11:54:04 -0700124 def epoll_suffix = "";
125 if (osdetector.classifier in ["linux-x86_64"]) {
126 // The native code is only pre-compiled on certain platforms.
127 epoll_suffix = ":" + osdetector.classifier
128 }
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800129 libraries = [
Carl Mastrangelo28253612016-05-16 10:23:53 -0700130 guava: "com.google.guava:guava:${guavaVersion}",
Jeff Pinnerb1cc7cc2015-02-25 10:17:23 -0800131 hpack: 'com.twitter:hpack:0.10.1',
nmittlerb897a892015-02-23 12:03:59 -0800132 jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
Eric Andersond52a7a22015-09-03 16:44:48 -0700133 oauth_client: 'com.google.auth:google-auth-library-oauth2-http:0.3.0',
Xudong Ma6d296e82015-09-21 10:39:00 -0700134 okhttp: 'com.squareup.okhttp:okhttp:2.5.0',
Xudong Mab121c462015-09-21 12:54:06 -0700135 okio: 'com.squareup.okio:okio:1.6.0',
Kun Zhangc5b94c72015-05-06 16:44:55 -0700136 protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
Kun Zhangbd23a8d2015-08-28 18:47:06 -0700137 protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${protobufNanoVersion}",
Eric Anderson446f0cb2016-05-07 11:24:15 -0700138 protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.7.7',
Carl Mastrangelo8e1fba72016-03-02 09:30:35 -0800139 protobuf_util: "com.google.protobuf:protobuf-java-util:${protobufVersion}",
nathanmittler164b7342014-12-15 09:58:05 -0800140
Eric Anderson511bea02016-04-11 18:49:58 -0700141 netty: 'io.netty:netty-codec-http2:[4.1.0.CR7]',
142 netty_epoll: 'io.netty:netty-transport-native-epoll:4.1.0.CR7' + epoll_suffix,
buchgr88d31742016-03-23 22:58:23 +0100143 netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork15:' + osdetector.classifier,
nathanmittler164b7342014-12-15 09:58:05 -0800144
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800145 // Test dependencies.
146 junit: 'junit:junit:4.11',
Carl Mastrangelob3bc7fc2016-04-01 15:18:23 -0700147 mockito: 'org.mockito:mockito-core:1.9.5',
Louis Ryana7049bc2016-03-23 13:18:04 -0700148 truth: 'com.google.truth:truth:0.28',
149
150 // Benchmark dependencies
151 hdrhistogram: 'org.hdrhistogram:HdrHistogram:2.1.8',
152 math: 'org.apache.commons:commons-math3:3.6',
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700153
154 // Jetty ALPN dependencies
155 jetty_alpn_agent: 'org.mortbay.jetty.alpn:jetty-alpn-agent:2.0.2'
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800156 ]
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800157 }
nathanmittler164b7342014-12-15 09:58:05 -0800158
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700159 // Define a separate configuration for managing the dependency on Jetty ALPN agent.
nmittler74cfe6c2015-05-22 12:25:10 -0700160 configurations {
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700161 alpnagent
nmittler9466eb52015-09-04 15:13:46 -0700162 tcnative
nmittler74cfe6c2015-05-22 12:25:10 -0700163 }
164
nathanmittler164b7342014-12-15 09:58:05 -0800165 dependencies {
166 testCompile libraries.junit,
167 libraries.mockito
nmittler74cfe6c2015-05-22 12:25:10 -0700168
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700169 // Configuration for modules that use Jetty ALPN agent
170 alpnagent libraries.jetty_alpn_agent
nmittler9466eb52015-09-04 15:13:46 -0700171
172 // Configuration for modules that use Netty tcnative (for OpenSSL).
173 tcnative libraries.netty_tcnative
nathanmittler164b7342014-12-15 09:58:05 -0800174 }
Eric Anderson192144e2015-03-02 13:31:14 -0800175
176 signing {
177 required false
178 sign configurations.archives
179 }
180
nmittler732cfc02015-03-03 07:59:13 -0800181 // Disable JavaDoc doclint on Java 8. It's annoying.
182 if (JavaVersion.current().isJava8Compatible()) {
183 allprojects {
184 tasks.withType(Javadoc) {
185 options.addStringOption('Xdoclint:none', '-quiet')
186 }
187 }
188 }
189
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800190 checkstyle {
191 configFile = file("$rootDir/checkstyle.xml")
Eric Anderson6ab27ab2016-04-18 09:15:25 -0700192 toolVersion = "6.17"
Eric Andersonad44f0a2015-05-05 08:54:51 -0700193 ignoreFailures = false
Eric Anderson26141b42015-03-21 10:59:17 -0700194 if (rootProject.hasProperty("checkstyle.ignoreFailures")) {
195 ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean()
196 }
Eric Andersonefa774b2015-09-15 10:34:14 -0700197 configProperties["rootDir"] = rootDir
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800198 }
199
200 checkstyleMain {
Kun Zhang693a7d22015-05-06 11:35:08 -0700201 source = fileTree(dir: "src/main", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800202 }
203
204 checkstyleTest {
Kun Zhang693a7d22015-05-06 11:35:08 -0700205 source = fileTree(dir: "src/test", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800206 }
207
Eric Anderson192144e2015-03-02 13:31:14 -0800208 task javadocJar(type: Jar) {
209 classifier = 'javadoc'
210 from javadoc
211 }
212
213 task sourcesJar(type: Jar) {
214 classifier = 'sources'
215 from sourceSets.main.allSource
216 }
217
218 artifacts {
219 archives javadocJar, sourcesJar
220 }
221
222 uploadArchives.repositories.mavenDeployer {
223 beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
zhangkun83da3c3f82015-03-11 18:03:31 -0700224 String stagingUrl
Kun Zhang2f749712015-05-06 13:10:28 -0700225 if (rootProject.hasProperty('repositoryId')) {
226 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
227 rootProject.repositoryId
zhangkun83da3c3f82015-03-11 18:03:31 -0700228 } else {
229 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
230 }
Kun Zhang2f749712015-05-06 13:10:28 -0700231 def configureAuth = {
232 if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
233 authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
234 }
Eric Anderson192144e2015-03-02 13:31:14 -0800235 }
Kun Zhang2f749712015-05-06 13:10:28 -0700236 repository(url: stagingUrl, configureAuth)
237 snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
Eric Anderson192144e2015-03-02 13:31:14 -0800238 }
239
240 [
241 install.repositories.mavenInstaller,
242 uploadArchives.repositories.mavenDeployer,
243 ]*.pom*.whenConfigured { pom ->
244 pom.project {
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700245 name "$project.group:$project.name"
Eric Anderson192144e2015-03-02 13:31:14 -0800246 description project.description
247 url 'https://github.com/grpc/grpc-java'
248
249 scm {
Eric Andersonb7354952016-04-08 08:37:07 -0700250 connection 'scm:git:https://github.com/grpc/grpc-java.git'
251 developerConnection 'scm:git:git@github.com:grpc/grpc-java.git'
Eric Anderson192144e2015-03-02 13:31:14 -0800252 url 'https://github.com/grpc/grpc-java'
253 }
254
255 licenses {
256 license {
257 name 'BSD 3-Clause'
258 url 'http://opensource.org/licenses/BSD-3-Clause'
259 }
260 }
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700261
262 developers {
263 developer {
264 id "grpc.io"
265 name "gRPC Contributors"
266 email "grpc-io@googlegroups.com"
267 url "http://grpc.io/"
268 // https://issues.gradle.org/browse/GRADLE-2719
269 organization = "Google, Inc."
270 organizationUrl "https://www.google.com"
271 }
272 }
Eric Anderson192144e2015-03-02 13:31:14 -0800273 }
Eric Anderson90db93b2016-04-08 13:47:30 -0700274 if (!(project.name in
275 ["grpc-stub", "grpc-protobuf", "grpc-protobuf-lite", "grpc-protobuf-nano"])) {
276 def core = pom.dependencies.find {dep -> dep.artifactId == 'grpc-core'}
277 if (core != null) {
278 // Depend on specific version of grpc-core because internal package is unstable
279 core.version = "[" + core.version + "]"
280 }
281 }
Eric Anderson192144e2015-03-02 13:31:14 -0800282 }
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700283 // At a test failure, log the stack trace to the console so that we don't
284 // have to open the HTML in a browser.
285 test {
286 testLogging {
287 exceptionFormat = 'full'
nmittler4ee2a652015-06-01 16:20:08 -0700288 showExceptions true
289 showCauses true
290 showStackTraces true
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700291 }
Eric Anderson56dca032016-02-12 08:48:41 -0800292 maxHeapSize = '1500m'
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700293 }
nathanmittler164b7342014-12-15 09:58:05 -0800294}