blob: 1ecfc0f916335effe3f2be5e73cb855aa85dbf3b [file] [log] [blame]
Kun Zhang4bc2d6d2015-04-17 10:49:11 -07001buildscript {
2 repositories {
3 mavenCentral()
4 mavenLocal()
5 }
6 dependencies {
nmittlerd59d6dc2015-08-31 12:55:18 -07007 classpath 'com.google.gradle:osdetector-gradle-plugin:1.3.0'
Kun Zhang4bc2d6d2015-04-17 10:49:11 -07008 }
9}
Eric Andersonb938ba52015-02-28 09:59:25 -080010
Louis Ryand6dc7902015-08-31 09:45:03 -070011configure(subprojects - project(":grpc-android")) {
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"
Kun Zhang4bc2d6d2015-04-17 10:49:11 -070016 apply plugin: "osdetector"
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
Louis Ryand6dc7902015-08-31 09:45:03 -070020 def properties = new Properties()
21 properties.load(new FileInputStream("version.properties"))
22
nmittlerf8314582015-01-27 10:25:39 -080023 group = "io.grpc"
Louis Ryand6dc7902015-08-31 09:45:03 -070024 version = properties.version
nathanmittler164b7342014-12-15 09:58:05 -080025
26 sourceCompatibility = 1.6
27 targetCompatibility = 1.6
28
29 repositories {
30 mavenCentral()
31 mavenLocal()
32 }
33
nmittler8c1d38a2015-06-01 08:31:00 -070034
Eric Anderson76d09552015-03-12 15:25:11 -070035 [compileJava, compileTestJava].each() {
36 it.options.compilerArgs += ["-Xlint:unchecked", "-Xlint:deprecation", "-Xlint:-options"]
37 it.options.encoding = "UTF-8"
nmittler02c953e2015-01-26 14:03:11 -080038 }
39
nmittler8c1d38a2015-06-01 08:31:00 -070040 jar.manifest {
41 attributes('Implementation-Title': name,
42 'Implementation-Version': version,
43 'Built-By': System.getProperty('user.name'),
44 'Built-JDK': System.getProperty('java.version'),
45 'Source-Compatibility': sourceCompatibility,
46 'Target-Compatibility': targetCompatibility)
47 }
48
Eric Anderson10fb2062015-05-05 10:28:38 -070049 javadoc.options {
50 encoding = 'UTF-8'
51 links 'https://docs.oracle.com/javase/8/docs/api/'
52 }
Eric Anderson14444a92015-03-11 16:44:38 -070053
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -080054 ext {
Kun Zhang6b1e7d62015-05-07 15:20:44 -070055 def exeSuffix = osdetector.os == 'windows' ? ".exe" : ""
56 protocPluginBaseName = 'protoc-gen-grpc-java'
57 javaPluginPath = "$rootDir/compiler/build/binaries/java_pluginExecutable/$protocPluginBaseName$exeSuffix"
58
Kun Zhangbd23a8d2015-08-28 18:47:06 -070059 protobufVersion = '3.0.0-beta-1'
60 protobufNanoVersion = '3.0.0-alpha-4'
Kun Zhang6b1e7d62015-05-07 15:20:44 -070061
Kun Zhang111f6dd2015-05-05 16:11:27 -070062 configureProtoCompilation = {
Kun Zhang35f77ee2015-06-22 16:29:30 -070063 String generatedSourcePath = "${projectDir}/src/generated"
Kun Zhang111f6dd2015-05-05 16:11:27 -070064 if (rootProject.childProjects.containsKey('grpc-compiler')) {
65 // Only when the codegen is built along with the project, will we be able to recompile
66 // the proto files.
67 project.apply plugin: 'com.google.protobuf'
Kun Zhang35f77ee2015-06-22 16:29:30 -070068 project.protobuf {
69 protoc {
70 if (project.hasProperty('protoc')) {
71 path = project.protoc
72 } else {
73 artifact = "com.google.protobuf:protoc:${protobufVersion}"
74 }
75 }
76 plugins {
77 grpc {
78 path = javaPluginPath
79 }
80 }
81 generateProtoTasks {
82 all().each { task ->
83 task.dependsOn ':grpc-compiler:java_pluginExecutable'
84 // Delete the generated sources first, so that we can be alerted if they are not re-compiled.
85 task.dependsOn deleteGeneratedSource
86 // Recompile protos when the codegen has been changed
87 task.inputs.file javaPluginPath
88 // Recompile protos when build.gradle has been changed, because
89 // it's possible the version of protoc has been changed.
90 task.inputs.file "${rootProject.projectDir}/build.gradle"
91 task.plugins {
92 grpc {}
Kun Zhang2cdc5e32015-05-11 16:58:28 -070093 }
94 }
95 }
Kun Zhang35f77ee2015-06-22 16:29:30 -070096 generatedFilesBaseDir = generatedSourcePath
97 }
98
99 task deleteGeneratedSource << {
100 project.delete project.fileTree(dir: generatedSourcePath)
Kun Zhang2cdc5e32015-05-11 16:58:28 -0700101 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700102 } else {
103 // Otherwise, we just use the checked-in generated code.
104 project.sourceSets {
105 main {
106 java {
Kun Zhang35f77ee2015-06-22 16:29:30 -0700107 srcDir "${generatedSourcePath}/main/java"
108 srcDir "${generatedSourcePath}/main/grpc"
Kun Zhang287a27a2015-05-07 17:32:31 -0700109 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700110 }
111 }
112 }
113 }
114
Eric Anderson65d73c02015-05-21 11:54:04 -0700115 def tcnative_suffix = "";
116 if (osdetector.classifier in ["linux-x86_64", "osx-x86_64", "windows-x86_64"]) {
117 // The native code is only pre-compiled on certain platforms.
118 tcnative_suffix = ":" + osdetector.classifier
nmittlerd59d6dc2015-08-31 12:55:18 -0700119 // Fedora variants use a different soname for OpenSSL than other linux distributions
120 // (see http://netty.io/wiki/forked-tomcat-native.html). Netty-tcnative, however
121 // assumes Fedora as the default "linux", while calling out "_debian" as a special
122 // build for debian-based systems. This should be inverted in future releases of
123 // netty-tcnative, but in the meantime we invert the logic manually here so that
124 // "debian" is used as the default linux distribution.
125 if (osdetector.os == "linux" && !osdetector.release.isLike("fedora")) {
126 tcnative_suffix += "_debian";
127 }
Eric Anderson65d73c02015-05-21 11:54:04 -0700128 }
129 def epoll_suffix = "";
130 if (osdetector.classifier in ["linux-x86_64"]) {
131 // The native code is only pre-compiled on certain platforms.
132 epoll_suffix = ":" + osdetector.classifier
133 }
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800134 libraries = [
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800135 guava: 'com.google.guava:guava:18.0',
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800136 // used to collect benchmark results
137 hdrhistogram: 'org.hdrhistogram:HdrHistogram:2.1.4',
Jeff Pinnerb1cc7cc2015-02-25 10:17:23 -0800138 hpack: 'com.twitter:hpack:0.10.1',
nmittlerb897a892015-02-23 12:03:59 -0800139 jsonp: 'org.glassfish:javax.json:1.0.4',
140 jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
Eric Andersond52a7a22015-09-03 16:44:48 -0700141 oauth_client: 'com.google.auth:google-auth-library-oauth2-http:0.3.0',
Xudong Mad242b222015-05-26 18:14:49 -0700142 okhttp: 'com.squareup.okhttp:okhttp:2.4.0',
Kun Zhangc5b94c72015-05-06 16:44:55 -0700143 protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
Kun Zhangbd23a8d2015-08-28 18:47:06 -0700144 protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${protobufNanoVersion}",
Kun Zhang5df6ab02015-08-13 14:28:40 -0700145 protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.7.0',
nathanmittler164b7342014-12-15 09:58:05 -0800146
nmittleraefefb52015-08-31 12:55:51 -0700147 netty: 'io.netty:netty-codec-http2:4.1.0.Beta6',
nmittlerd59d6dc2015-08-31 12:55:18 -0700148 netty_tcnative: 'io.netty:netty-tcnative:1.1.33.Fork6' + tcnative_suffix,
nmittleraefefb52015-08-31 12:55:51 -0700149 netty_transport_native_epoll: 'io.netty:netty-transport-native-epoll:4.1.0.Beta6' + epoll_suffix,
nathanmittler164b7342014-12-15 09:58:05 -0800150
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800151 // Test dependencies.
152 junit: 'junit:junit:4.11',
Eric Anderson192144e2015-03-02 13:31:14 -0800153 mockito: 'org.mockito:mockito-core:1.10.19'
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800154 ]
155
156 // Determine the correct version of Jetty ALPN boot to use based
157 // on the Java version.
158 def alpnboot_version = '8.1.2.v20141202'
159 if (JavaVersion.current().ordinal() < JavaVersion.VERSION_1_8.ordinal()) {
nmittler247ffb12015-07-24 11:19:34 -0700160 alpnboot_version = '7.1.3.v20150130'
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800161 }
162
163 alpnboot_package_name = 'org.mortbay.jetty.alpn:alpn-boot:' + alpnboot_version
164 }
nathanmittler164b7342014-12-15 09:58:05 -0800165
nmittler74cfe6c2015-05-22 12:25:10 -0700166 // Define a separate configuration for managing the dependency on Jetty alpnboot jar.
167 configurations {
168 alpnboot
nmittler9466eb52015-09-04 15:13:46 -0700169 tcnative
nmittler74cfe6c2015-05-22 12:25:10 -0700170 }
171
nathanmittler164b7342014-12-15 09:58:05 -0800172 dependencies {
173 testCompile libraries.junit,
174 libraries.mockito
nmittler74cfe6c2015-05-22 12:25:10 -0700175
nmittler9466eb52015-09-04 15:13:46 -0700176 // Configuration for modules that use Jetty ALPN
nmittler74cfe6c2015-05-22 12:25:10 -0700177 alpnboot alpnboot_package_name
nmittler9466eb52015-09-04 15:13:46 -0700178
179 // Configuration for modules that use Netty tcnative (for OpenSSL).
180 tcnative libraries.netty_tcnative
nathanmittler164b7342014-12-15 09:58:05 -0800181 }
Eric Anderson192144e2015-03-02 13:31:14 -0800182
183 signing {
184 required false
185 sign configurations.archives
186 }
187
nmittler732cfc02015-03-03 07:59:13 -0800188 // Disable JavaDoc doclint on Java 8. It's annoying.
189 if (JavaVersion.current().isJava8Compatible()) {
190 allprojects {
191 tasks.withType(Javadoc) {
192 options.addStringOption('Xdoclint:none', '-quiet')
193 }
194 }
195 }
196
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800197 checkstyle {
198 configFile = file("$rootDir/checkstyle.xml")
Xudong Ma9aae6f62015-04-06 21:04:56 +0800199 toolVersion = "6.5"
Eric Andersonad44f0a2015-05-05 08:54:51 -0700200 ignoreFailures = false
Eric Anderson26141b42015-03-21 10:59:17 -0700201 if (rootProject.hasProperty("checkstyle.ignoreFailures")) {
202 ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean()
203 }
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800204 }
205
206 checkstyleMain {
Kun Zhang693a7d22015-05-06 11:35:08 -0700207 source = fileTree(dir: "src/main", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800208 }
209
210 checkstyleTest {
Kun Zhang693a7d22015-05-06 11:35:08 -0700211 source = fileTree(dir: "src/test", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800212 }
213
Eric Anderson192144e2015-03-02 13:31:14 -0800214 task javadocJar(type: Jar) {
215 classifier = 'javadoc'
216 from javadoc
217 }
218
219 task sourcesJar(type: Jar) {
220 classifier = 'sources'
221 from sourceSets.main.allSource
222 }
223
224 artifacts {
225 archives javadocJar, sourcesJar
226 }
227
228 uploadArchives.repositories.mavenDeployer {
229 beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
zhangkun83da3c3f82015-03-11 18:03:31 -0700230 String stagingUrl
Kun Zhang2f749712015-05-06 13:10:28 -0700231 if (rootProject.hasProperty('repositoryId')) {
232 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
233 rootProject.repositoryId
zhangkun83da3c3f82015-03-11 18:03:31 -0700234 } else {
235 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
236 }
Kun Zhang2f749712015-05-06 13:10:28 -0700237 def configureAuth = {
238 if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
239 authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
240 }
Eric Anderson192144e2015-03-02 13:31:14 -0800241 }
Kun Zhang2f749712015-05-06 13:10:28 -0700242 repository(url: stagingUrl, configureAuth)
243 snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
Eric Anderson192144e2015-03-02 13:31:14 -0800244 }
245
246 [
247 install.repositories.mavenInstaller,
248 uploadArchives.repositories.mavenDeployer,
249 ]*.pom*.whenConfigured { pom ->
250 pom.project {
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700251 name "$project.group:$project.name"
Eric Anderson192144e2015-03-02 13:31:14 -0800252 description project.description
253 url 'https://github.com/grpc/grpc-java'
254
255 scm {
256 connection 'scm:svn:https://github.com/grpc/grpc-java.git'
257 developerConnection 'scm:svn:git@github.com:grpc/grpc-java.git'
258 url 'https://github.com/grpc/grpc-java'
259 }
260
261 licenses {
262 license {
263 name 'BSD 3-Clause'
264 url 'http://opensource.org/licenses/BSD-3-Clause'
265 }
266 }
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700267
268 developers {
269 developer {
270 id "grpc.io"
271 name "gRPC Contributors"
272 email "grpc-io@googlegroups.com"
273 url "http://grpc.io/"
274 // https://issues.gradle.org/browse/GRADLE-2719
275 organization = "Google, Inc."
276 organizationUrl "https://www.google.com"
277 }
278 }
Eric Anderson192144e2015-03-02 13:31:14 -0800279 }
280 }
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700281 // At a test failure, log the stack trace to the console so that we don't
282 // have to open the HTML in a browser.
283 test {
284 testLogging {
285 exceptionFormat = 'full'
nmittler4ee2a652015-06-01 16:20:08 -0700286 showExceptions true
287 showCauses true
288 showStackTraces true
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700289 }
290 }
nathanmittler164b7342014-12-15 09:58:05 -0800291}