blob: 8c8b64772d9b969ced84d9b52034aaef539f9daa [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"
Eric Anderson46379da2016-07-01 11:43:14 -070022 version = "1.0.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'
Eric Andersondbef1af2016-05-23 12:05:41 -070062 protobufVersion = '3.0.0-beta-3'
Kun Zhange2ed2e82016-01-27 08:26:19 -080063 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 }
Eric Andersondbef1af2016-05-23 12:05:41 -0700126
127 compileJava {
128 // Protobuf-generated code produces some warnings.
129 options.compilerArgs = compileJava.options.compilerArgs + ["-Xlint:-deprecation"]
130 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700131 }
132
Eric Anderson65d73c02015-05-21 11:54:04 -0700133 def epoll_suffix = "";
134 if (osdetector.classifier in ["linux-x86_64"]) {
135 // The native code is only pre-compiled on certain platforms.
136 epoll_suffix = ":" + osdetector.classifier
137 }
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800138 libraries = [
Carl Mastrangelo28253612016-05-16 10:23:53 -0700139 guava: "com.google.guava:guava:${guavaVersion}",
Jeff Pinnerb1cc7cc2015-02-25 10:17:23 -0800140 hpack: 'com.twitter:hpack:0.10.1',
nmittlerb897a892015-02-23 12:03:59 -0800141 jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
Kun Zhangdef237d2016-06-14 13:51:24 -0700142 oauth_client: 'com.google.auth:google-auth-library-oauth2-http:0.4.0',
143 google_auth_credentials: 'com.google.auth:google-auth-library-credentials:0.4.0',
Xudong Ma6d296e82015-09-21 10:39:00 -0700144 okhttp: 'com.squareup.okhttp:okhttp:2.5.0',
Xudong Mab121c462015-09-21 12:54:06 -0700145 okio: 'com.squareup.okio:okio:1.6.0',
Kun Zhangc5b94c72015-05-06 16:44:55 -0700146 protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
Kun Zhangbd23a8d2015-08-28 18:47:06 -0700147 protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${protobufNanoVersion}",
Eric Anderson446f0cb2016-05-07 11:24:15 -0700148 protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.7.7',
Carl Mastrangelo8e1fba72016-03-02 09:30:35 -0800149 protobuf_util: "com.google.protobuf:protobuf-java-util:${protobufVersion}",
nathanmittler164b7342014-12-15 09:58:05 -0800150
Eric Anderson3f5a1542016-06-08 10:25:46 -0700151 netty: 'io.netty:netty-codec-http2:[4.1.1.Final]',
152 netty_epoll: 'io.netty:netty-transport-native-epoll:4.1.1.Final' + epoll_suffix,
Eric Anderson03d94502016-06-07 14:55:33 -0700153 netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork17',
nathanmittler164b7342014-12-15 09:58:05 -0800154
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800155 // Test dependencies.
156 junit: 'junit:junit:4.11',
Carl Mastrangelob3bc7fc2016-04-01 15:18:23 -0700157 mockito: 'org.mockito:mockito-core:1.9.5',
Louis Ryana7049bc2016-03-23 13:18:04 -0700158 truth: 'com.google.truth:truth:0.28',
159
160 // Benchmark dependencies
161 hdrhistogram: 'org.hdrhistogram:HdrHistogram:2.1.8',
162 math: 'org.apache.commons:commons-math3:3.6',
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700163
164 // Jetty ALPN dependencies
Eric Andersonaa92d6c2016-05-19 11:41:03 -0700165 jetty_alpn_agent: 'org.mortbay.jetty.alpn:jetty-alpn-agent:2.0.3'
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800166 ]
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800167 }
nathanmittler164b7342014-12-15 09:58:05 -0800168
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700169 // Define a separate configuration for managing the dependency on Jetty ALPN agent.
nmittler74cfe6c2015-05-22 12:25:10 -0700170 configurations {
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700171 alpnagent
nmittler9466eb52015-09-04 15:13:46 -0700172 tcnative
nmittler74cfe6c2015-05-22 12:25:10 -0700173 }
174
nathanmittler164b7342014-12-15 09:58:05 -0800175 dependencies {
176 testCompile libraries.junit,
177 libraries.mockito
nmittler74cfe6c2015-05-22 12:25:10 -0700178
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700179 // Configuration for modules that use Jetty ALPN agent
180 alpnagent libraries.jetty_alpn_agent
nmittler9466eb52015-09-04 15:13:46 -0700181
182 // Configuration for modules that use Netty tcnative (for OpenSSL).
183 tcnative libraries.netty_tcnative
nathanmittler164b7342014-12-15 09:58:05 -0800184 }
Eric Anderson192144e2015-03-02 13:31:14 -0800185
186 signing {
187 required false
188 sign configurations.archives
189 }
190
nmittler732cfc02015-03-03 07:59:13 -0800191 // Disable JavaDoc doclint on Java 8. It's annoying.
192 if (JavaVersion.current().isJava8Compatible()) {
193 allprojects {
194 tasks.withType(Javadoc) {
195 options.addStringOption('Xdoclint:none', '-quiet')
196 }
197 }
198 }
199
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800200 checkstyle {
201 configFile = file("$rootDir/checkstyle.xml")
Eric Anderson6ab27ab2016-04-18 09:15:25 -0700202 toolVersion = "6.17"
Eric Andersonad44f0a2015-05-05 08:54:51 -0700203 ignoreFailures = false
Eric Anderson26141b42015-03-21 10:59:17 -0700204 if (rootProject.hasProperty("checkstyle.ignoreFailures")) {
205 ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean()
206 }
Eric Andersonefa774b2015-09-15 10:34:14 -0700207 configProperties["rootDir"] = rootDir
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800208 }
209
210 checkstyleMain {
Kun Zhang693a7d22015-05-06 11:35:08 -0700211 source = fileTree(dir: "src/main", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800212 }
213
214 checkstyleTest {
Kun Zhang693a7d22015-05-06 11:35:08 -0700215 source = fileTree(dir: "src/test", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800216 }
217
Eric Anderson192144e2015-03-02 13:31:14 -0800218 task javadocJar(type: Jar) {
219 classifier = 'javadoc'
220 from javadoc
221 }
222
223 task sourcesJar(type: Jar) {
224 classifier = 'sources'
225 from sourceSets.main.allSource
226 }
227
228 artifacts {
229 archives javadocJar, sourcesJar
230 }
231
232 uploadArchives.repositories.mavenDeployer {
233 beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
zhangkun83da3c3f82015-03-11 18:03:31 -0700234 String stagingUrl
Kun Zhang2f749712015-05-06 13:10:28 -0700235 if (rootProject.hasProperty('repositoryId')) {
236 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
237 rootProject.repositoryId
zhangkun83da3c3f82015-03-11 18:03:31 -0700238 } else {
239 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
240 }
Kun Zhang2f749712015-05-06 13:10:28 -0700241 def configureAuth = {
242 if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
243 authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
244 }
Eric Anderson192144e2015-03-02 13:31:14 -0800245 }
Kun Zhang2f749712015-05-06 13:10:28 -0700246 repository(url: stagingUrl, configureAuth)
247 snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
Eric Anderson192144e2015-03-02 13:31:14 -0800248 }
249
250 [
251 install.repositories.mavenInstaller,
252 uploadArchives.repositories.mavenDeployer,
253 ]*.pom*.whenConfigured { pom ->
254 pom.project {
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700255 name "$project.group:$project.name"
Eric Anderson192144e2015-03-02 13:31:14 -0800256 description project.description
257 url 'https://github.com/grpc/grpc-java'
258
259 scm {
Eric Andersonb7354952016-04-08 08:37:07 -0700260 connection 'scm:git:https://github.com/grpc/grpc-java.git'
261 developerConnection 'scm:git:git@github.com:grpc/grpc-java.git'
Eric Anderson192144e2015-03-02 13:31:14 -0800262 url 'https://github.com/grpc/grpc-java'
263 }
264
265 licenses {
266 license {
267 name 'BSD 3-Clause'
268 url 'http://opensource.org/licenses/BSD-3-Clause'
269 }
270 }
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700271
272 developers {
273 developer {
274 id "grpc.io"
275 name "gRPC Contributors"
276 email "grpc-io@googlegroups.com"
277 url "http://grpc.io/"
278 // https://issues.gradle.org/browse/GRADLE-2719
279 organization = "Google, Inc."
280 organizationUrl "https://www.google.com"
281 }
282 }
Eric Anderson192144e2015-03-02 13:31:14 -0800283 }
Eric Anderson90db93b2016-04-08 13:47:30 -0700284 if (!(project.name in
285 ["grpc-stub", "grpc-protobuf", "grpc-protobuf-lite", "grpc-protobuf-nano"])) {
286 def core = pom.dependencies.find {dep -> dep.artifactId == 'grpc-core'}
287 if (core != null) {
288 // Depend on specific version of grpc-core because internal package is unstable
289 core.version = "[" + core.version + "]"
290 }
291 }
Eric Anderson192144e2015-03-02 13:31:14 -0800292 }
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700293 // At a test failure, log the stack trace to the console so that we don't
294 // have to open the HTML in a browser.
295 test {
296 testLogging {
297 exceptionFormat = 'full'
nmittler4ee2a652015-06-01 16:20:08 -0700298 showExceptions true
299 showCauses true
300 showStackTraces true
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700301 }
Eric Anderson56dca032016-02-12 08:48:41 -0800302 maxHeapSize = '1500m'
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700303 }
nathanmittler164b7342014-12-15 09:58:05 -0800304}