blob: 14b36de27a034cacd20e6c7d241a92088195572a [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
Eric Anderson76d09552015-03-12 15:25:11 -070031 [compileJava, compileTestJava].each() {
32 it.options.compilerArgs += ["-Xlint:unchecked", "-Xlint:deprecation", "-Xlint:-options"]
33 it.options.encoding = "UTF-8"
nmittler02c953e2015-01-26 14:03:11 -080034 }
35
Eric Anderson10fb2062015-05-05 10:28:38 -070036 javadoc.options {
37 encoding = 'UTF-8'
38 links 'https://docs.oracle.com/javase/8/docs/api/'
39 }
Eric Anderson14444a92015-03-11 16:44:38 -070040
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -080041 ext {
Kun Zhang6b1e7d62015-05-07 15:20:44 -070042 def exeSuffix = osdetector.os == 'windows' ? ".exe" : ""
43 protocPluginBaseName = 'protoc-gen-grpc-java'
44 javaPluginPath = "$rootDir/compiler/build/binaries/java_pluginExecutable/$protocPluginBaseName$exeSuffix"
45
Kun Zhangc5b94c72015-05-06 16:44:55 -070046 protobufVersion = '3.0.0-alpha-2'
Kun Zhang6b1e7d62015-05-07 15:20:44 -070047
Kun Zhang111f6dd2015-05-05 16:11:27 -070048 configureProtoCompilation = {
Kun Zhang2cdc5e32015-05-11 16:58:28 -070049 String generatedSourcePath = 'src/generated'
Kun Zhang111f6dd2015-05-05 16:11:27 -070050 if (rootProject.childProjects.containsKey('grpc-compiler')) {
51 // Only when the codegen is built along with the project, will we be able to recompile
52 // the proto files.
53 project.apply plugin: 'com.google.protobuf'
Kun Zhang287a27a2015-05-07 17:32:31 -070054 project.protobufCodeGenPlugins = ["grpc:$javaPluginPath"]
Kun Zhang9805e272015-05-12 17:03:19 -070055 if (project.hasProperty('protoc')) {
56 project.protocPath = project.protoc
57 } else {
58 project.protocDep = "com.google.protobuf:protoc:${protobufVersion}"
59 }
Kun Zhang111f6dd2015-05-05 16:11:27 -070060 project.generatedFileDir = "${projectDir}/src/generated"
Kun Zhang568d25d2015-05-15 10:37:57 -070061 task deleteGeneratedSource << {
62 project.delete project.fileTree(dir: generatedSourcePath)
63 }
Kun Zhang111f6dd2015-05-05 16:11:27 -070064 project.afterEvaluate {
65 generateProto.dependsOn ':grpc-compiler:java_pluginExecutable'
Kun Zhang568d25d2015-05-15 10:37:57 -070066 // Delete the generated sources first, so that we can be alerted if they are not re-compiled.
67 generateProto.dependsOn deleteGeneratedSource
Kun Zhang6b1e7d62015-05-07 15:20:44 -070068 // Recompile protos when the codegen has been changed
69 generateProto.inputs.file javaPluginPath
70 // Recompile protos when build.gradle has been changed, because
71 // it's possible the version of protoc has been changed.
72 generateProto.inputs.file "${rootProject.projectDir}/build.gradle"
Kun Zhang111f6dd2015-05-05 16:11:27 -070073 }
Kun Zhang2cdc5e32015-05-11 16:58:28 -070074
75 project.sourceSets {
76 main {
77 proto {
78 plugins {
79 grpc { }
80 }
81 }
82 }
83 }
Kun Zhang111f6dd2015-05-05 16:11:27 -070084 } else {
85 // Otherwise, we just use the checked-in generated code.
86 project.sourceSets {
87 main {
88 java {
Kun Zhang2cdc5e32015-05-11 16:58:28 -070089 srcDir "${generatedSourcePath}/main"
Kun Zhang287a27a2015-05-07 17:32:31 -070090 }
Kun Zhang111f6dd2015-05-05 16:11:27 -070091 }
92 }
93 }
94 }
95
Eric Anderson65d73c02015-05-21 11:54:04 -070096 def tcnative_suffix = "";
97 if (osdetector.classifier in ["linux-x86_64", "osx-x86_64", "windows-x86_64"]) {
98 // The native code is only pre-compiled on certain platforms.
99 tcnative_suffix = ":" + osdetector.classifier
100 }
101 def epoll_suffix = "";
102 if (osdetector.classifier in ["linux-x86_64"]) {
103 // The native code is only pre-compiled on certain platforms.
104 epoll_suffix = ":" + osdetector.classifier
105 }
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800106 libraries = [
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800107 guava: 'com.google.guava:guava:18.0',
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800108 // used to collect benchmark results
109 hdrhistogram: 'org.hdrhistogram:HdrHistogram:2.1.4',
Jeff Pinnerb1cc7cc2015-02-25 10:17:23 -0800110 hpack: 'com.twitter:hpack:0.10.1',
nmittlerb897a892015-02-23 12:03:59 -0800111 javaee_api: 'javax:javaee-api:7.0',
112 jsonp: 'org.glassfish:javax.json:1.0.4',
113 jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
Louis Ryan767a12c2015-03-02 15:05:09 -0800114 oauth_client: 'com.google.auth:google-auth-library-oauth2-http:0.1.0',
Xudong Ma6affc8d2015-05-22 15:38:12 -0700115 okhttp: 'com.squareup.okhttp:okhttp:2.3.0',
Kun Zhangc5b94c72015-05-06 16:44:55 -0700116 protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
117 protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${protobufVersion}",
Kun Zhang9805e272015-05-12 17:03:19 -0700118 protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.4.1',
nathanmittler164b7342014-12-15 09:58:05 -0800119
Mark Kelly589afef2015-05-09 10:59:20 +0100120 netty: 'io.netty:netty-codec-http2:4.1.0.Beta5',
Eric Anderson65d73c02015-05-21 11:54:04 -0700121 netty_tcnative: 'io.netty:netty-tcnative:1.1.33.Fork2' + tcnative_suffix,
122 netty_transport_native_epoll: 'io.netty:netty-transport-native-epoll:4.1.0.Beta5' + epoll_suffix,
nathanmittler164b7342014-12-15 09:58:05 -0800123
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800124 // Test dependencies.
125 junit: 'junit:junit:4.11',
Eric Anderson192144e2015-03-02 13:31:14 -0800126 mockito: 'org.mockito:mockito-core:1.10.19'
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800127 ]
128
129 // Determine the correct version of Jetty ALPN boot to use based
130 // on the Java version.
131 def alpnboot_version = '8.1.2.v20141202'
132 if (JavaVersion.current().ordinal() < JavaVersion.VERSION_1_8.ordinal()) {
133 alpnboot_version = '7.1.2.v20141202'
134 }
135
136 alpnboot_package_name = 'org.mortbay.jetty.alpn:alpn-boot:' + alpnboot_version
137 }
nathanmittler164b7342014-12-15 09:58:05 -0800138
nmittler74cfe6c2015-05-22 12:25:10 -0700139 // Define a separate configuration for managing the dependency on Jetty alpnboot jar.
140 configurations {
141 alpnboot
142 }
143
nathanmittler164b7342014-12-15 09:58:05 -0800144 dependencies {
145 testCompile libraries.junit,
146 libraries.mockito
nmittler74cfe6c2015-05-22 12:25:10 -0700147
148 // Make the Jetty alpnboot jar available to submodules via the alpnboot configuration.
149 alpnboot alpnboot_package_name
nathanmittler164b7342014-12-15 09:58:05 -0800150 }
Eric Anderson192144e2015-03-02 13:31:14 -0800151
152 signing {
153 required false
154 sign configurations.archives
155 }
156
nmittler732cfc02015-03-03 07:59:13 -0800157 // Disable JavaDoc doclint on Java 8. It's annoying.
158 if (JavaVersion.current().isJava8Compatible()) {
159 allprojects {
160 tasks.withType(Javadoc) {
161 options.addStringOption('Xdoclint:none', '-quiet')
162 }
163 }
164 }
165
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800166 checkstyle {
167 configFile = file("$rootDir/checkstyle.xml")
Xudong Ma9aae6f62015-04-06 21:04:56 +0800168 toolVersion = "6.5"
Eric Andersonad44f0a2015-05-05 08:54:51 -0700169 ignoreFailures = false
Eric Anderson26141b42015-03-21 10:59:17 -0700170 if (rootProject.hasProperty("checkstyle.ignoreFailures")) {
171 ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean()
172 }
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800173 }
174
175 checkstyleMain {
Kun Zhang693a7d22015-05-06 11:35:08 -0700176 source = fileTree(dir: "src/main", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800177 }
178
179 checkstyleTest {
Kun Zhang693a7d22015-05-06 11:35:08 -0700180 source = fileTree(dir: "src/test", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800181 }
182
Eric Anderson192144e2015-03-02 13:31:14 -0800183 task javadocJar(type: Jar) {
184 classifier = 'javadoc'
185 from javadoc
186 }
187
188 task sourcesJar(type: Jar) {
189 classifier = 'sources'
190 from sourceSets.main.allSource
191 }
192
193 artifacts {
194 archives javadocJar, sourcesJar
195 }
196
197 uploadArchives.repositories.mavenDeployer {
198 beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
zhangkun83da3c3f82015-03-11 18:03:31 -0700199 String stagingUrl
Kun Zhang2f749712015-05-06 13:10:28 -0700200 if (rootProject.hasProperty('repositoryId')) {
201 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
202 rootProject.repositoryId
zhangkun83da3c3f82015-03-11 18:03:31 -0700203 } else {
204 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
205 }
Kun Zhang2f749712015-05-06 13:10:28 -0700206 def configureAuth = {
207 if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
208 authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
209 }
Eric Anderson192144e2015-03-02 13:31:14 -0800210 }
Kun Zhang2f749712015-05-06 13:10:28 -0700211 repository(url: stagingUrl, configureAuth)
212 snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
Eric Anderson192144e2015-03-02 13:31:14 -0800213 }
214
215 [
216 install.repositories.mavenInstaller,
217 uploadArchives.repositories.mavenDeployer,
218 ]*.pom*.whenConfigured { pom ->
219 pom.project {
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700220 name "$project.group:$project.name"
Eric Anderson192144e2015-03-02 13:31:14 -0800221 description project.description
222 url 'https://github.com/grpc/grpc-java'
223
224 scm {
225 connection 'scm:svn:https://github.com/grpc/grpc-java.git'
226 developerConnection 'scm:svn:git@github.com:grpc/grpc-java.git'
227 url 'https://github.com/grpc/grpc-java'
228 }
229
230 licenses {
231 license {
232 name 'BSD 3-Clause'
233 url 'http://opensource.org/licenses/BSD-3-Clause'
234 }
235 }
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700236
237 developers {
238 developer {
239 id "grpc.io"
240 name "gRPC Contributors"
241 email "grpc-io@googlegroups.com"
242 url "http://grpc.io/"
243 // https://issues.gradle.org/browse/GRADLE-2719
244 organization = "Google, Inc."
245 organizationUrl "https://www.google.com"
246 }
247 }
Eric Anderson192144e2015-03-02 13:31:14 -0800248 }
249 }
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700250 // At a test failure, log the stack trace to the console so that we don't
251 // have to open the HTML in a browser.
252 test {
253 testLogging {
254 exceptionFormat = 'full'
255 }
256 }
nathanmittler164b7342014-12-15 09:58:05 -0800257}