blob: 33735b20545274bb05c0ff2ec1a69e7bee452463 [file] [log] [blame]
Kun Zhang4bc2d6d2015-04-17 10:49:11 -07001buildscript {
2 repositories {
3 mavenCentral()
4 mavenLocal()
5 }
6 dependencies {
7 classpath 'com.google.gradle:osdetector-gradle-plugin:1.2.1'
8 }
9}
Eric Andersonb938ba52015-02-28 09:59:25 -080010
nathanmittler164b7342014-12-15 09:58:05 -080011subprojects {
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
nmittlerf8314582015-01-27 10:25:39 -080020 group = "io.grpc"
Eric Andersonb0619c42015-05-26 13:40:13 -070021 version = "0.8.0-SNAPSHOT"
nathanmittler164b7342014-12-15 09:58:05 -080022
23 sourceCompatibility = 1.6
24 targetCompatibility = 1.6
25
26 repositories {
27 mavenCentral()
28 mavenLocal()
29 }
30
nmittler8c1d38a2015-06-01 08:31:00 -070031
Eric Anderson76d09552015-03-12 15:25:11 -070032 [compileJava, compileTestJava].each() {
33 it.options.compilerArgs += ["-Xlint:unchecked", "-Xlint:deprecation", "-Xlint:-options"]
34 it.options.encoding = "UTF-8"
nmittler02c953e2015-01-26 14:03:11 -080035 }
36
nmittler8c1d38a2015-06-01 08:31:00 -070037 jar.manifest {
38 attributes('Implementation-Title': name,
39 'Implementation-Version': version,
40 'Built-By': System.getProperty('user.name'),
41 'Built-JDK': System.getProperty('java.version'),
42 'Source-Compatibility': sourceCompatibility,
43 'Target-Compatibility': targetCompatibility)
44 }
45
Eric Anderson10fb2062015-05-05 10:28:38 -070046 javadoc.options {
47 encoding = 'UTF-8'
48 links 'https://docs.oracle.com/javase/8/docs/api/'
49 }
Eric Anderson14444a92015-03-11 16:44:38 -070050
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -080051 ext {
Kun Zhang6b1e7d62015-05-07 15:20:44 -070052 def exeSuffix = osdetector.os == 'windows' ? ".exe" : ""
53 protocPluginBaseName = 'protoc-gen-grpc-java'
54 javaPluginPath = "$rootDir/compiler/build/binaries/java_pluginExecutable/$protocPluginBaseName$exeSuffix"
55
Kun Zhangaf9fb6d2015-06-30 16:08:46 -070056 protobufVersion = '3.0.0-alpha-3.1'
Kun Zhang6b1e7d62015-05-07 15:20:44 -070057
Kun Zhang111f6dd2015-05-05 16:11:27 -070058 configureProtoCompilation = {
Kun Zhang35f77ee2015-06-22 16:29:30 -070059 String generatedSourcePath = "${projectDir}/src/generated"
Kun Zhang111f6dd2015-05-05 16:11:27 -070060 if (rootProject.childProjects.containsKey('grpc-compiler')) {
61 // Only when the codegen is built along with the project, will we be able to recompile
62 // the proto files.
63 project.apply plugin: 'com.google.protobuf'
Kun Zhang35f77ee2015-06-22 16:29:30 -070064 project.protobuf {
65 protoc {
66 if (project.hasProperty('protoc')) {
67 path = project.protoc
68 } else {
69 artifact = "com.google.protobuf:protoc:${protobufVersion}"
70 }
71 }
72 plugins {
73 grpc {
74 path = javaPluginPath
75 }
76 }
77 generateProtoTasks {
78 all().each { task ->
79 task.dependsOn ':grpc-compiler:java_pluginExecutable'
80 // Delete the generated sources first, so that we can be alerted if they are not re-compiled.
81 task.dependsOn deleteGeneratedSource
82 // Recompile protos when the codegen has been changed
83 task.inputs.file javaPluginPath
84 // Recompile protos when build.gradle has been changed, because
85 // it's possible the version of protoc has been changed.
86 task.inputs.file "${rootProject.projectDir}/build.gradle"
87 task.plugins {
88 grpc {}
Kun Zhang2cdc5e32015-05-11 16:58:28 -070089 }
90 }
91 }
Kun Zhang35f77ee2015-06-22 16:29:30 -070092 generatedFilesBaseDir = generatedSourcePath
93 }
94
95 task deleteGeneratedSource << {
96 project.delete project.fileTree(dir: generatedSourcePath)
Kun Zhang2cdc5e32015-05-11 16:58:28 -070097 }
Kun Zhang111f6dd2015-05-05 16:11:27 -070098 } else {
99 // Otherwise, we just use the checked-in generated code.
100 project.sourceSets {
101 main {
102 java {
Kun Zhang35f77ee2015-06-22 16:29:30 -0700103 srcDir "${generatedSourcePath}/main/java"
104 srcDir "${generatedSourcePath}/main/grpc"
Kun Zhang287a27a2015-05-07 17:32:31 -0700105 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700106 }
107 }
108 }
109 }
110
Eric Anderson65d73c02015-05-21 11:54:04 -0700111 def tcnative_suffix = "";
112 if (osdetector.classifier in ["linux-x86_64", "osx-x86_64", "windows-x86_64"]) {
113 // The native code is only pre-compiled on certain platforms.
114 tcnative_suffix = ":" + osdetector.classifier
115 }
116 def epoll_suffix = "";
117 if (osdetector.classifier in ["linux-x86_64"]) {
118 // The native code is only pre-compiled on certain platforms.
119 epoll_suffix = ":" + osdetector.classifier
120 }
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800121 libraries = [
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800122 guava: 'com.google.guava:guava:18.0',
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800123 // used to collect benchmark results
124 hdrhistogram: 'org.hdrhistogram:HdrHistogram:2.1.4',
Jeff Pinnerb1cc7cc2015-02-25 10:17:23 -0800125 hpack: 'com.twitter:hpack:0.10.1',
nmittlerb897a892015-02-23 12:03:59 -0800126 javaee_api: 'javax:javaee-api:7.0',
127 jsonp: 'org.glassfish:javax.json:1.0.4',
128 jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
Louis Ryan767a12c2015-03-02 15:05:09 -0800129 oauth_client: 'com.google.auth:google-auth-library-oauth2-http:0.1.0',
Xudong Mad242b222015-05-26 18:14:49 -0700130 okhttp: 'com.squareup.okhttp:okhttp:2.4.0',
Kun Zhangc5b94c72015-05-06 16:44:55 -0700131 protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
132 protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${protobufVersion}",
Kun Zhang35f77ee2015-06-22 16:29:30 -0700133 protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.5.0',
nathanmittler164b7342014-12-15 09:58:05 -0800134
Mark Kelly589afef2015-05-09 10:59:20 +0100135 netty: 'io.netty:netty-codec-http2:4.1.0.Beta5',
Eric Anderson65d73c02015-05-21 11:54:04 -0700136 netty_tcnative: 'io.netty:netty-tcnative:1.1.33.Fork2' + tcnative_suffix,
137 netty_transport_native_epoll: 'io.netty:netty-transport-native-epoll:4.1.0.Beta5' + epoll_suffix,
nathanmittler164b7342014-12-15 09:58:05 -0800138
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800139 // Test dependencies.
140 junit: 'junit:junit:4.11',
Eric Anderson192144e2015-03-02 13:31:14 -0800141 mockito: 'org.mockito:mockito-core:1.10.19'
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800142 ]
143
144 // Determine the correct version of Jetty ALPN boot to use based
145 // on the Java version.
146 def alpnboot_version = '8.1.2.v20141202'
147 if (JavaVersion.current().ordinal() < JavaVersion.VERSION_1_8.ordinal()) {
148 alpnboot_version = '7.1.2.v20141202'
149 }
150
151 alpnboot_package_name = 'org.mortbay.jetty.alpn:alpn-boot:' + alpnboot_version
152 }
nathanmittler164b7342014-12-15 09:58:05 -0800153
nmittler74cfe6c2015-05-22 12:25:10 -0700154 // Define a separate configuration for managing the dependency on Jetty alpnboot jar.
155 configurations {
156 alpnboot
157 }
158
nathanmittler164b7342014-12-15 09:58:05 -0800159 dependencies {
160 testCompile libraries.junit,
161 libraries.mockito
nmittler74cfe6c2015-05-22 12:25:10 -0700162
163 // Make the Jetty alpnboot jar available to submodules via the alpnboot configuration.
164 alpnboot alpnboot_package_name
nathanmittler164b7342014-12-15 09:58:05 -0800165 }
Eric Anderson192144e2015-03-02 13:31:14 -0800166
167 signing {
168 required false
169 sign configurations.archives
170 }
171
nmittler732cfc02015-03-03 07:59:13 -0800172 // Disable JavaDoc doclint on Java 8. It's annoying.
173 if (JavaVersion.current().isJava8Compatible()) {
174 allprojects {
175 tasks.withType(Javadoc) {
176 options.addStringOption('Xdoclint:none', '-quiet')
177 }
178 }
179 }
180
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800181 checkstyle {
182 configFile = file("$rootDir/checkstyle.xml")
Xudong Ma9aae6f62015-04-06 21:04:56 +0800183 toolVersion = "6.5"
Eric Andersonad44f0a2015-05-05 08:54:51 -0700184 ignoreFailures = false
Eric Anderson26141b42015-03-21 10:59:17 -0700185 if (rootProject.hasProperty("checkstyle.ignoreFailures")) {
186 ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean()
187 }
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800188 }
189
190 checkstyleMain {
Kun Zhang693a7d22015-05-06 11:35:08 -0700191 source = fileTree(dir: "src/main", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800192 }
193
194 checkstyleTest {
Kun Zhang693a7d22015-05-06 11:35:08 -0700195 source = fileTree(dir: "src/test", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800196 }
197
Eric Anderson192144e2015-03-02 13:31:14 -0800198 task javadocJar(type: Jar) {
199 classifier = 'javadoc'
200 from javadoc
201 }
202
203 task sourcesJar(type: Jar) {
204 classifier = 'sources'
205 from sourceSets.main.allSource
206 }
207
208 artifacts {
209 archives javadocJar, sourcesJar
210 }
211
212 uploadArchives.repositories.mavenDeployer {
213 beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
zhangkun83da3c3f82015-03-11 18:03:31 -0700214 String stagingUrl
Kun Zhang2f749712015-05-06 13:10:28 -0700215 if (rootProject.hasProperty('repositoryId')) {
216 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
217 rootProject.repositoryId
zhangkun83da3c3f82015-03-11 18:03:31 -0700218 } else {
219 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
220 }
Kun Zhang2f749712015-05-06 13:10:28 -0700221 def configureAuth = {
222 if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
223 authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
224 }
Eric Anderson192144e2015-03-02 13:31:14 -0800225 }
Kun Zhang2f749712015-05-06 13:10:28 -0700226 repository(url: stagingUrl, configureAuth)
227 snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
Eric Anderson192144e2015-03-02 13:31:14 -0800228 }
229
230 [
231 install.repositories.mavenInstaller,
232 uploadArchives.repositories.mavenDeployer,
233 ]*.pom*.whenConfigured { pom ->
234 pom.project {
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700235 name "$project.group:$project.name"
Eric Anderson192144e2015-03-02 13:31:14 -0800236 description project.description
237 url 'https://github.com/grpc/grpc-java'
238
239 scm {
240 connection 'scm:svn:https://github.com/grpc/grpc-java.git'
241 developerConnection 'scm:svn:git@github.com:grpc/grpc-java.git'
242 url 'https://github.com/grpc/grpc-java'
243 }
244
245 licenses {
246 license {
247 name 'BSD 3-Clause'
248 url 'http://opensource.org/licenses/BSD-3-Clause'
249 }
250 }
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700251
252 developers {
253 developer {
254 id "grpc.io"
255 name "gRPC Contributors"
256 email "grpc-io@googlegroups.com"
257 url "http://grpc.io/"
258 // https://issues.gradle.org/browse/GRADLE-2719
259 organization = "Google, Inc."
260 organizationUrl "https://www.google.com"
261 }
262 }
Eric Anderson192144e2015-03-02 13:31:14 -0800263 }
264 }
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700265 // At a test failure, log the stack trace to the console so that we don't
266 // have to open the HTML in a browser.
267 test {
268 testLogging {
269 exceptionFormat = 'full'
nmittler4ee2a652015-06-01 16:20:08 -0700270 showExceptions true
271 showCauses true
272 showStackTraces true
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700273 }
274 }
nathanmittler164b7342014-12-15 09:58:05 -0800275}