blob: 3c38e9aa4fba8b8822f74e1b7cfa44e4205e1783 [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 Anderson853ccaa2016-01-15 16:12:57 -080022 version = "0.13.0-SNAPSHOT"
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
Kun Zhangbd23a8d2015-08-28 18:47:06 -070057 protobufVersion = '3.0.0-beta-1'
58 protobufNanoVersion = '3.0.0-alpha-4'
Kun Zhang6b1e7d62015-05-07 15:20:44 -070059
Kun Zhang111f6dd2015-05-05 16:11:27 -070060 configureProtoCompilation = {
Kun Zhang35f77ee2015-06-22 16:29:30 -070061 String generatedSourcePath = "${projectDir}/src/generated"
Kun Zhang111f6dd2015-05-05 16:11:27 -070062 if (rootProject.childProjects.containsKey('grpc-compiler')) {
63 // Only when the codegen is built along with the project, will we be able to recompile
64 // the proto files.
65 project.apply plugin: 'com.google.protobuf'
Kun Zhang35f77ee2015-06-22 16:29:30 -070066 project.protobuf {
67 protoc {
68 if (project.hasProperty('protoc')) {
69 path = project.protoc
70 } else {
71 artifact = "com.google.protobuf:protoc:${protobufVersion}"
72 }
73 }
74 plugins {
75 grpc {
76 path = javaPluginPath
77 }
78 }
79 generateProtoTasks {
80 all().each { task ->
81 task.dependsOn ':grpc-compiler:java_pluginExecutable'
82 // Delete the generated sources first, so that we can be alerted if they are not re-compiled.
83 task.dependsOn deleteGeneratedSource
84 // Recompile protos when the codegen has been changed
85 task.inputs.file javaPluginPath
86 // Recompile protos when build.gradle has been changed, because
87 // it's possible the version of protoc has been changed.
88 task.inputs.file "${rootProject.projectDir}/build.gradle"
89 task.plugins {
90 grpc {}
Kun Zhang2cdc5e32015-05-11 16:58:28 -070091 }
92 }
93 }
Kun Zhang35f77ee2015-06-22 16:29:30 -070094 generatedFilesBaseDir = generatedSourcePath
95 }
96
97 task deleteGeneratedSource << {
98 project.delete project.fileTree(dir: generatedSourcePath)
Kun Zhang2cdc5e32015-05-11 16:58:28 -070099 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700100 } else {
101 // Otherwise, we just use the checked-in generated code.
102 project.sourceSets {
103 main {
104 java {
Kun Zhang35f77ee2015-06-22 16:29:30 -0700105 srcDir "${generatedSourcePath}/main/java"
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700106 srcDir "${generatedSourcePath}/main/javanano"
Kun Zhang35f77ee2015-06-22 16:29:30 -0700107 srcDir "${generatedSourcePath}/main/grpc"
Kun Zhang287a27a2015-05-07 17:32:31 -0700108 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700109 }
Eric Andersoncea8e8e2015-10-27 19:53:18 -0700110 test {
111 java {
112 srcDir "${generatedSourcePath}/test/java"
113 srcDir "${generatedSourcePath}/test/javanano"
114 srcDir "${generatedSourcePath}/test/grpc"
115 }
116 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700117 }
118 }
119 }
120
Eric Anderson551323f2015-09-17 15:38:12 -0700121 def tcnative_suffix = osdetector.classifier;
122 // Fedora variants use a different soname for OpenSSL than other linux distributions
123 // (see http://netty.io/wiki/forked-tomcat-native.html).
124 if (osdetector.os == "linux" && osdetector.release.isLike("fedora")) {
nmittlerb82ac312015-09-18 12:30:19 -0700125 tcnative_suffix += "-fedora";
Eric Anderson551323f2015-09-17 15:38:12 -0700126 }
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 = [
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800134 guava: 'com.google.guava:guava:18.0',
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800135 // used to collect benchmark results
136 hdrhistogram: 'org.hdrhistogram:HdrHistogram:2.1.4',
Jeff Pinnerb1cc7cc2015-02-25 10:17:23 -0800137 hpack: 'com.twitter:hpack:0.10.1',
nmittlerb897a892015-02-23 12:03:59 -0800138 jsonp: 'org.glassfish:javax.json:1.0.4',
139 jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
Eric Andersond52a7a22015-09-03 16:44:48 -0700140 oauth_client: 'com.google.auth:google-auth-library-oauth2-http:0.3.0',
Xudong Ma6d296e82015-09-21 10:39:00 -0700141 okhttp: 'com.squareup.okhttp:okhttp:2.5.0',
Xudong Mab121c462015-09-21 12:54:06 -0700142 okio: 'com.squareup.okio:okio:1.6.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 Zhangd3d253e2016-01-26 15:31:53 -0800145 protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.7.4',
nathanmittler164b7342014-12-15 09:58:05 -0800146
nmittlerebed5a62015-11-13 13:32:08 -0800147 netty: 'io.netty:netty-codec-http2:4.1.0.Beta8',
148 netty_epoll: 'io.netty:netty-transport-native-epoll:4.1.0.Beta8' + epoll_suffix,
149 netty_tcnative: 'io.netty:netty-tcnative:1.1.33.Fork9:' + tcnative_suffix,
nathanmittler164b7342014-12-15 09:58:05 -0800150
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800151 // Test dependencies.
152 junit: 'junit:junit:4.11',
Carl Mastrangeloc53b5172015-10-28 12:57:10 -0700153 mockito: 'org.mockito:mockito-core:1.9.5'
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 Andersonefa774b2015-09-15 10:34:14 -0700204 configProperties["rootDir"] = rootDir
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800205 }
206
207 checkstyleMain {
Kun Zhang693a7d22015-05-06 11:35:08 -0700208 source = fileTree(dir: "src/main", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800209 }
210
211 checkstyleTest {
Kun Zhang693a7d22015-05-06 11:35:08 -0700212 source = fileTree(dir: "src/test", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800213 }
214
Eric Anderson192144e2015-03-02 13:31:14 -0800215 task javadocJar(type: Jar) {
216 classifier = 'javadoc'
217 from javadoc
218 }
219
220 task sourcesJar(type: Jar) {
221 classifier = 'sources'
222 from sourceSets.main.allSource
223 }
224
225 artifacts {
226 archives javadocJar, sourcesJar
227 }
228
229 uploadArchives.repositories.mavenDeployer {
230 beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
zhangkun83da3c3f82015-03-11 18:03:31 -0700231 String stagingUrl
Kun Zhang2f749712015-05-06 13:10:28 -0700232 if (rootProject.hasProperty('repositoryId')) {
233 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
234 rootProject.repositoryId
zhangkun83da3c3f82015-03-11 18:03:31 -0700235 } else {
236 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
237 }
Kun Zhang2f749712015-05-06 13:10:28 -0700238 def configureAuth = {
239 if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
240 authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
241 }
Eric Anderson192144e2015-03-02 13:31:14 -0800242 }
Kun Zhang2f749712015-05-06 13:10:28 -0700243 repository(url: stagingUrl, configureAuth)
244 snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
Eric Anderson192144e2015-03-02 13:31:14 -0800245 }
246
247 [
248 install.repositories.mavenInstaller,
249 uploadArchives.repositories.mavenDeployer,
250 ]*.pom*.whenConfigured { pom ->
251 pom.project {
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700252 name "$project.group:$project.name"
Eric Anderson192144e2015-03-02 13:31:14 -0800253 description project.description
254 url 'https://github.com/grpc/grpc-java'
255
256 scm {
257 connection 'scm:svn:https://github.com/grpc/grpc-java.git'
258 developerConnection 'scm:svn:git@github.com:grpc/grpc-java.git'
259 url 'https://github.com/grpc/grpc-java'
260 }
261
262 licenses {
263 license {
264 name 'BSD 3-Clause'
265 url 'http://opensource.org/licenses/BSD-3-Clause'
266 }
267 }
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700268
269 developers {
270 developer {
271 id "grpc.io"
272 name "gRPC Contributors"
273 email "grpc-io@googlegroups.com"
274 url "http://grpc.io/"
275 // https://issues.gradle.org/browse/GRADLE-2719
276 organization = "Google, Inc."
277 organizationUrl "https://www.google.com"
278 }
279 }
Eric Anderson192144e2015-03-02 13:31:14 -0800280 }
281 }
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700282 // At a test failure, log the stack trace to the console so that we don't
283 // have to open the HTML in a browser.
284 test {
285 testLogging {
286 exceptionFormat = 'full'
nmittler4ee2a652015-06-01 16:20:08 -0700287 showExceptions true
288 showCauses true
289 showStackTraces true
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700290 }
291 }
nathanmittler164b7342014-12-15 09:58:05 -0800292}