blob: e1f75dbe50d3ff01840aa2407188490c2046bd12 [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"
Eric Anderson3c03eb72016-07-10 11:40:12 -070035 if (rootProject.hasProperty('failOnWarnings') && rootProject.failOnWarnings.toBoolean()) {
36 it.options.compilerArgs += ["-Werror"]
37 }
nmittler02c953e2015-01-26 14:03:11 -080038 }
39
Eric Anderson641cb352016-05-24 14:29:52 -070040 compileTestJava {
41 // serialVersionUID is basically guaranteed to be useless in our tests
42 options.compilerArgs += ["-Xlint:-serial"]
43 }
44
nmittler8c1d38a2015-06-01 08:31:00 -070045 jar.manifest {
46 attributes('Implementation-Title': name,
47 'Implementation-Version': version,
48 'Built-By': System.getProperty('user.name'),
49 'Built-JDK': System.getProperty('java.version'),
50 'Source-Compatibility': sourceCompatibility,
51 'Target-Compatibility': targetCompatibility)
52 }
53
Eric Anderson10fb2062015-05-05 10:28:38 -070054 javadoc.options {
55 encoding = 'UTF-8'
56 links 'https://docs.oracle.com/javase/8/docs/api/'
57 }
Eric Anderson14444a92015-03-11 16:44:38 -070058
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -080059 ext {
Kun Zhang6b1e7d62015-05-07 15:20:44 -070060 def exeSuffix = osdetector.os == 'windows' ? ".exe" : ""
61 protocPluginBaseName = 'protoc-gen-grpc-java'
Eric Anderson46ce4092016-01-26 12:13:06 -080062 javaPluginPath = "$rootDir/compiler/build/exe/java_plugin/$protocPluginBaseName$exeSuffix"
Kun Zhang6b1e7d62015-05-07 15:20:44 -070063
Carl Mastrangelo28253612016-05-16 10:23:53 -070064 guavaVersion = '19.0'
Eric Andersondbef1af2016-05-23 12:05:41 -070065 protobufVersion = '3.0.0-beta-3'
Kun Zhange2ed2e82016-01-27 08:26:19 -080066 protobufNanoVersion = '3.0.0-alpha-5'
Kun Zhang6b1e7d62015-05-07 15:20:44 -070067
Kun Zhang111f6dd2015-05-05 16:11:27 -070068 configureProtoCompilation = {
Kun Zhang35f77ee2015-06-22 16:29:30 -070069 String generatedSourcePath = "${projectDir}/src/generated"
Kun Zhang111f6dd2015-05-05 16:11:27 -070070 if (rootProject.childProjects.containsKey('grpc-compiler')) {
71 // Only when the codegen is built along with the project, will we be able to recompile
72 // the proto files.
73 project.apply plugin: 'com.google.protobuf'
Kun Zhang35f77ee2015-06-22 16:29:30 -070074 project.protobuf {
75 protoc {
76 if (project.hasProperty('protoc')) {
77 path = project.protoc
78 } else {
79 artifact = "com.google.protobuf:protoc:${protobufVersion}"
80 }
81 }
82 plugins {
83 grpc {
84 path = javaPluginPath
85 }
86 }
87 generateProtoTasks {
88 all().each { task ->
89 task.dependsOn ':grpc-compiler:java_pluginExecutable'
90 // Delete the generated sources first, so that we can be alerted if they are not re-compiled.
Eric Andersone9b4d152016-04-19 11:54:04 -070091 task.dependsOn 'deleteGeneratedSource' + task.sourceSet.name
Kun Zhang35f77ee2015-06-22 16:29:30 -070092 // Recompile protos when the codegen has been changed
93 task.inputs.file javaPluginPath
94 // Recompile protos when build.gradle has been changed, because
95 // it's possible the version of protoc has been changed.
96 task.inputs.file "${rootProject.projectDir}/build.gradle"
97 task.plugins {
98 grpc {}
Kun Zhang2cdc5e32015-05-11 16:58:28 -070099 }
100 }
101 }
Kun Zhang35f77ee2015-06-22 16:29:30 -0700102 generatedFilesBaseDir = generatedSourcePath
103 }
104
Eric Andersone9b4d152016-04-19 11:54:04 -0700105 sourceSets.each { sourceSet ->
106 task "deleteGeneratedSource${sourceSet.name}" << {
107 project.delete project.fileTree(dir: generatedSourcePath + '/' + sourceSet.name)
108 }
Kun Zhang2cdc5e32015-05-11 16:58:28 -0700109 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700110 } else {
111 // Otherwise, we just use the checked-in generated code.
112 project.sourceSets {
113 main {
114 java {
Kun Zhang35f77ee2015-06-22 16:29:30 -0700115 srcDir "${generatedSourcePath}/main/java"
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700116 srcDir "${generatedSourcePath}/main/javanano"
Kun Zhang35f77ee2015-06-22 16:29:30 -0700117 srcDir "${generatedSourcePath}/main/grpc"
Kun Zhang287a27a2015-05-07 17:32:31 -0700118 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700119 }
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700120 test {
121 java {
122 srcDir "${generatedSourcePath}/test/java"
123 srcDir "${generatedSourcePath}/test/javanano"
124 srcDir "${generatedSourcePath}/test/grpc"
125 }
126 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700127 }
128 }
Eric Andersondbef1af2016-05-23 12:05:41 -0700129
130 compileJava {
131 // Protobuf-generated code produces some warnings.
132 options.compilerArgs = compileJava.options.compilerArgs + ["-Xlint:-deprecation"]
133 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700134 }
135
Eric Anderson65d73c02015-05-21 11:54:04 -0700136 def epoll_suffix = "";
137 if (osdetector.classifier in ["linux-x86_64"]) {
138 // The native code is only pre-compiled on certain platforms.
139 epoll_suffix = ":" + osdetector.classifier
140 }
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800141 libraries = [
Carl Mastrangelo28253612016-05-16 10:23:53 -0700142 guava: "com.google.guava:guava:${guavaVersion}",
Jeff Pinnerb1cc7cc2015-02-25 10:17:23 -0800143 hpack: 'com.twitter:hpack:0.10.1',
nmittlerb897a892015-02-23 12:03:59 -0800144 jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
Kun Zhangdef237d2016-06-14 13:51:24 -0700145 oauth_client: 'com.google.auth:google-auth-library-oauth2-http:0.4.0',
146 google_auth_credentials: 'com.google.auth:google-auth-library-credentials:0.4.0',
Xudong Ma6d296e82015-09-21 10:39:00 -0700147 okhttp: 'com.squareup.okhttp:okhttp:2.5.0',
Xudong Mab121c462015-09-21 12:54:06 -0700148 okio: 'com.squareup.okio:okio:1.6.0',
Kun Zhangc5b94c72015-05-06 16:44:55 -0700149 protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
Kun Zhangbd23a8d2015-08-28 18:47:06 -0700150 protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${protobufNanoVersion}",
Eric Anderson446f0cb2016-05-07 11:24:15 -0700151 protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.7.7',
Carl Mastrangelo8e1fba72016-03-02 09:30:35 -0800152 protobuf_util: "com.google.protobuf:protobuf-java-util:${protobufVersion}",
nathanmittler164b7342014-12-15 09:58:05 -0800153
Eric Anderson3f5a1542016-06-08 10:25:46 -0700154 netty: 'io.netty:netty-codec-http2:[4.1.1.Final]',
155 netty_epoll: 'io.netty:netty-transport-native-epoll:4.1.1.Final' + epoll_suffix,
Eric Anderson03d94502016-06-07 14:55:33 -0700156 netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork17',
nathanmittler164b7342014-12-15 09:58:05 -0800157
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800158 // Test dependencies.
159 junit: 'junit:junit:4.11',
Carl Mastrangelob3bc7fc2016-04-01 15:18:23 -0700160 mockito: 'org.mockito:mockito-core:1.9.5',
Louis Ryana7049bc2016-03-23 13:18:04 -0700161 truth: 'com.google.truth:truth:0.28',
162
163 // Benchmark dependencies
164 hdrhistogram: 'org.hdrhistogram:HdrHistogram:2.1.8',
165 math: 'org.apache.commons:commons-math3:3.6',
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700166
167 // Jetty ALPN dependencies
Eric Andersonaa92d6c2016-05-19 11:41:03 -0700168 jetty_alpn_agent: 'org.mortbay.jetty.alpn:jetty-alpn-agent:2.0.3'
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800169 ]
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800170 }
nathanmittler164b7342014-12-15 09:58:05 -0800171
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700172 // Define a separate configuration for managing the dependency on Jetty ALPN agent.
nmittler74cfe6c2015-05-22 12:25:10 -0700173 configurations {
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700174 alpnagent
nmittler9466eb52015-09-04 15:13:46 -0700175 tcnative
nmittler74cfe6c2015-05-22 12:25:10 -0700176 }
177
nathanmittler164b7342014-12-15 09:58:05 -0800178 dependencies {
179 testCompile libraries.junit,
180 libraries.mockito
nmittler74cfe6c2015-05-22 12:25:10 -0700181
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700182 // Configuration for modules that use Jetty ALPN agent
183 alpnagent libraries.jetty_alpn_agent
nmittler9466eb52015-09-04 15:13:46 -0700184
185 // Configuration for modules that use Netty tcnative (for OpenSSL).
186 tcnative libraries.netty_tcnative
nathanmittler164b7342014-12-15 09:58:05 -0800187 }
Eric Anderson192144e2015-03-02 13:31:14 -0800188
189 signing {
190 required false
191 sign configurations.archives
192 }
193
nmittler732cfc02015-03-03 07:59:13 -0800194 // Disable JavaDoc doclint on Java 8. It's annoying.
195 if (JavaVersion.current().isJava8Compatible()) {
196 allprojects {
197 tasks.withType(Javadoc) {
198 options.addStringOption('Xdoclint:none', '-quiet')
199 }
200 }
201 }
202
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800203 checkstyle {
204 configFile = file("$rootDir/checkstyle.xml")
Eric Anderson6ab27ab2016-04-18 09:15:25 -0700205 toolVersion = "6.17"
Eric Andersonad44f0a2015-05-05 08:54:51 -0700206 ignoreFailures = false
Eric Anderson26141b42015-03-21 10:59:17 -0700207 if (rootProject.hasProperty("checkstyle.ignoreFailures")) {
208 ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean()
209 }
Eric Andersonefa774b2015-09-15 10:34:14 -0700210 configProperties["rootDir"] = rootDir
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800211 }
212
213 checkstyleMain {
Kun Zhang693a7d22015-05-06 11:35:08 -0700214 source = fileTree(dir: "src/main", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800215 }
216
217 checkstyleTest {
Kun Zhang693a7d22015-05-06 11:35:08 -0700218 source = fileTree(dir: "src/test", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800219 }
220
Eric Anderson192144e2015-03-02 13:31:14 -0800221 task javadocJar(type: Jar) {
222 classifier = 'javadoc'
223 from javadoc
224 }
225
226 task sourcesJar(type: Jar) {
227 classifier = 'sources'
228 from sourceSets.main.allSource
229 }
230
231 artifacts {
232 archives javadocJar, sourcesJar
233 }
234
235 uploadArchives.repositories.mavenDeployer {
236 beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
zhangkun83da3c3f82015-03-11 18:03:31 -0700237 String stagingUrl
Kun Zhang2f749712015-05-06 13:10:28 -0700238 if (rootProject.hasProperty('repositoryId')) {
239 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
240 rootProject.repositoryId
zhangkun83da3c3f82015-03-11 18:03:31 -0700241 } else {
242 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
243 }
Kun Zhang2f749712015-05-06 13:10:28 -0700244 def configureAuth = {
245 if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
246 authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
247 }
Eric Anderson192144e2015-03-02 13:31:14 -0800248 }
Kun Zhang2f749712015-05-06 13:10:28 -0700249 repository(url: stagingUrl, configureAuth)
250 snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
Eric Anderson192144e2015-03-02 13:31:14 -0800251 }
252
253 [
254 install.repositories.mavenInstaller,
255 uploadArchives.repositories.mavenDeployer,
256 ]*.pom*.whenConfigured { pom ->
257 pom.project {
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700258 name "$project.group:$project.name"
Eric Anderson192144e2015-03-02 13:31:14 -0800259 description project.description
260 url 'https://github.com/grpc/grpc-java'
261
262 scm {
Eric Andersonb7354952016-04-08 08:37:07 -0700263 connection 'scm:git:https://github.com/grpc/grpc-java.git'
264 developerConnection 'scm:git:git@github.com:grpc/grpc-java.git'
Eric Anderson192144e2015-03-02 13:31:14 -0800265 url 'https://github.com/grpc/grpc-java'
266 }
267
268 licenses {
269 license {
270 name 'BSD 3-Clause'
271 url 'http://opensource.org/licenses/BSD-3-Clause'
272 }
273 }
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700274
275 developers {
276 developer {
277 id "grpc.io"
278 name "gRPC Contributors"
279 email "grpc-io@googlegroups.com"
280 url "http://grpc.io/"
281 // https://issues.gradle.org/browse/GRADLE-2719
282 organization = "Google, Inc."
283 organizationUrl "https://www.google.com"
284 }
285 }
Eric Anderson192144e2015-03-02 13:31:14 -0800286 }
Eric Anderson90db93b2016-04-08 13:47:30 -0700287 if (!(project.name in
288 ["grpc-stub", "grpc-protobuf", "grpc-protobuf-lite", "grpc-protobuf-nano"])) {
289 def core = pom.dependencies.find {dep -> dep.artifactId == 'grpc-core'}
290 if (core != null) {
291 // Depend on specific version of grpc-core because internal package is unstable
292 core.version = "[" + core.version + "]"
293 }
294 }
Eric Anderson192144e2015-03-02 13:31:14 -0800295 }
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700296 // At a test failure, log the stack trace to the console so that we don't
297 // have to open the HTML in a browser.
298 test {
299 testLogging {
300 exceptionFormat = 'full'
nmittler4ee2a652015-06-01 16:20:08 -0700301 showExceptions true
302 showCauses true
303 showStackTraces true
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700304 }
Eric Anderson56dca032016-02-12 08:48:41 -0800305 maxHeapSize = '1500m'
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700306 }
nathanmittler164b7342014-12-15 09:58:05 -0800307}