blob: 4c25986f29569cfe4fa6e9a601e555b5a901710b [file] [log] [blame]
Kun Zhang4bc2d6d2015-04-17 10:49:11 -07001buildscript {
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -07002 repositories {
3 mavenLocal()
4 maven { url "https://plugins.gradle.org/m2/" }
Eric Anderson675080b2017-02-24 14:53:23 -08005 }
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -07006 dependencies {
7 classpath "com.diffplug.spotless:spotless-plugin-gradle:3.13.0"
8 classpath 'com.google.gradle:osdetector-gradle-plugin:1.4.0'
9 classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.4.0'
10 classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.13'
11 classpath 'net.ltgt.gradle:gradle-apt-plugin:0.13'
12 classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.5"
13 classpath 'me.champeau.gradle:japicmp-gradle-plugin:0.2.5'
14 }
Kun Zhang4bc2d6d2015-04-17 10:49:11 -070015}
Eric Andersonb938ba52015-02-28 09:59:25 -080016
Louis Ryan540b4d32015-09-04 13:26:24 -070017subprojects {
Eric Andersonc3e8dae2015-01-30 14:58:07 -080018 apply plugin: "checkstyle"
nathanmittler164b7342014-12-15 09:58:05 -080019 apply plugin: "java"
20 apply plugin: "maven"
nmittler52f42202015-01-21 14:30:14 -080021 apply plugin: "idea"
Eric Anderson192144e2015-03-02 13:31:14 -080022 apply plugin: "signing"
Eric Anderson041cdb12015-05-05 12:29:26 -070023 apply plugin: "jacoco"
nathanmittler164b7342014-12-15 09:58:05 -080024
Eric Anderson6164b7b2017-08-26 17:10:18 -070025 apply plugin: "me.champeau.gradle.jmh"
nmittlerc4bcf142015-09-16 15:15:10 -070026 apply plugin: "com.google.osdetector"
Eric Anderson42aa64c2017-02-02 13:48:12 -080027 // The plugin only has an effect if a signature is specified
28 apply plugin: "ru.vyarus.animalsniffer"
Eric Anderson675080b2017-02-24 14:53:23 -080029 if (!rootProject.hasProperty('errorProne') || rootProject.errorProne.toBoolean()) {
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -070030 apply plugin: "net.ltgt.errorprone"
31 apply plugin: "net.ltgt.apt"
Eric Anderson982541b2017-04-26 13:33:27 -070032
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -070033 dependencies {
34 // The ErrorProne plugin defaults to the latest, which would break our
35 // build if error prone releases a new version with a new check
36 errorprone 'com.google.errorprone:error_prone_core:2.2.0'
37 apt 'com.google.guava:guava-beta-checker:1.0'
Eric Anderson982541b2017-04-26 13:33:27 -070038 }
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -070039 } else {
40 // Remove per-project error-prone checker config
41 allprojects {
42 afterEvaluate { project ->
43 project.tasks.withType(JavaCompile) {
44 options.compilerArgs.removeAll { it.startsWith("-Xep") }
45 }
46 }
47 }
Eric Anderson675080b2017-02-24 14:53:23 -080048 }
zpencer5713ebc2017-07-15 12:41:20 -070049 // TODO(zpencer): remove when intellij 2017.2 is released
50 // https://github.com/gradle/gradle/issues/2315
51 idea.module.inheritOutputDirs = true
nmittlerc4bcf142015-09-16 15:15:10 -070052
nmittlerf8314582015-01-27 10:25:39 -080053 group = "io.grpc"
ZHANG Dapeng8a3e6232018-06-04 16:08:31 -070054 version = "1.14.0-SNAPSHOT" // CURRENT_GRPC_VERSION
nathanmittler164b7342014-12-15 09:58:05 -080055
56 sourceCompatibility = 1.6
57 targetCompatibility = 1.6
58
59 repositories {
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -070060 maven { // The google mirror is less flaky than mavenCentral()
61 url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
zpencer066ad3c2018-03-01 19:11:24 -080062 mavenLocal()
nathanmittler164b7342014-12-15 09:58:05 -080063 }
64
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -070065 [
66 compileJava,
67 compileTestJava,
68 compileJmhJava
69 ].each() {
70 it.options.compilerArgs += [
71 "-Xlint:all",
72 "-Xlint:-options",
73 "-Xlint:-path"
74 ]
Eric Anderson76d09552015-03-12 15:25:11 -070075 it.options.encoding = "UTF-8"
Eric Anderson3c03eb72016-07-10 11:40:12 -070076 if (rootProject.hasProperty('failOnWarnings') && rootProject.failOnWarnings.toBoolean()) {
77 it.options.compilerArgs += ["-Werror"]
78 }
nmittler02c953e2015-01-26 14:03:11 -080079 }
80
Eric Anderson641cb352016-05-24 14:29:52 -070081 compileTestJava {
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -070082 // serialVersionUID is basically guaranteed to be useless in our tests
83 // LinkedList doesn't hurt much in tests and has lots of usages
84 options.compilerArgs += [
85 "-Xlint:-serial",
86 "-Xep:JdkObsolete:OFF"
87 ]
Eric Anderson641cb352016-05-24 14:29:52 -070088 }
89
nmittler8c1d38a2015-06-01 08:31:00 -070090 jar.manifest {
91 attributes('Implementation-Title': name,
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -070092 'Implementation-Version': version,
93 'Built-By': System.getProperty('user.name'),
94 'Built-JDK': System.getProperty('java.version'),
95 'Source-Compatibility': sourceCompatibility,
96 'Target-Compatibility': targetCompatibility)
nmittler8c1d38a2015-06-01 08:31:00 -070097 }
98
Eric Anderson10fb2062015-05-05 10:28:38 -070099 javadoc.options {
100 encoding = 'UTF-8'
ZHANG Dapeng66ebcb12017-05-17 08:52:07 -0700101 use = true
Eric Anderson10fb2062015-05-05 10:28:38 -0700102 links 'https://docs.oracle.com/javase/8/docs/api/'
103 }
Eric Anderson14444a92015-03-11 16:44:38 -0700104
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800105 ext {
Kun Zhang6b1e7d62015-05-07 15:20:44 -0700106 def exeSuffix = osdetector.os == 'windows' ? ".exe" : ""
107 protocPluginBaseName = 'protoc-gen-grpc-java'
Eric Anderson46ce4092016-01-26 12:13:06 -0800108 javaPluginPath = "$rootDir/compiler/build/exe/java_plugin/$protocPluginBaseName$exeSuffix"
Kun Zhang6b1e7d62015-05-07 15:20:44 -0700109
Carl Mastrangelo4388d902018-05-23 17:16:45 -0700110 nettyVersion = '4.1.25.Final'
Eric Anderson5f0ee3a2018-03-23 15:45:05 -0700111 guavaVersion = '20.0'
Kun Zhang86d64122018-01-05 16:40:20 -0800112 protobufVersion = '3.5.1'
113 protocVersion = '3.5.1-1'
Kun Zhange2ed2e82016-01-27 08:26:19 -0800114 protobufNanoVersion = '3.0.0-alpha-5'
Bogdan Drutu2a127ce2018-06-04 15:27:27 -0700115 opencensusVersion = '0.12.3'
Kun Zhang6b1e7d62015-05-07 15:20:44 -0700116
Kun Zhang111f6dd2015-05-05 16:11:27 -0700117 configureProtoCompilation = {
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700118 String generatedSourcePath = "${projectDir}/src/generated"
119 if (rootProject.childProjects.containsKey('grpc-compiler')) {
120 // Only when the codegen is built along with the project, will we be able to recompile
121 // the proto files.
122 project.apply plugin: 'com.google.protobuf'
123 project.protobuf {
124 protoc {
125 if (project.hasProperty('protoc')) {
126 path = project.protoc
127 } else {
128 artifact = "com.google.protobuf:protoc:${protocVersion}"
129 }
ZHANG Dapenge1091252016-07-21 16:35:18 -0700130 }
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700131 plugins { grpc { path = javaPluginPath } }
132 generateProtoTasks {
133 all().each { task ->
134 task.dependsOn ':grpc-compiler:java_pluginExecutable'
135 // Delete the generated sources first, so that we can be alerted if they are not re-compiled.
136 task.dependsOn 'deleteGeneratedSource' + task.sourceSet.name
137 // Recompile protos when the codegen has been changed
138 task.inputs.file javaPluginPath
139 // Recompile protos when build.gradle has been changed, because
140 // it's possible the version of protoc has been changed.
141 task.inputs.file "${rootProject.projectDir}/build.gradle"
142 task.plugins { grpc { option 'noversion' } }
143 }
144 }
145 generatedFilesBaseDir = generatedSourcePath
Kun Zhang2cdc5e32015-05-11 16:58:28 -0700146 }
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700147
148 sourceSets.each { sourceSet ->
149 task "deleteGeneratedSource${sourceSet.name}" {
150 doLast {
151 project.delete project.fileTree(dir: generatedSourcePath + '/' + sourceSet.name)
152 }
153 }
154 }
155 } else {
156 // Otherwise, we just use the checked-in generated code.
157 project.sourceSets {
158 main {
159 java {
160 srcDir "${generatedSourcePath}/main/java"
161 srcDir "${generatedSourcePath}/main/javanano"
162 srcDir "${generatedSourcePath}/main/grpc"
163 }
164 }
165 test {
166 java {
167 srcDir "${generatedSourcePath}/test/java"
168 srcDir "${generatedSourcePath}/test/javanano"
169 srcDir "${generatedSourcePath}/test/grpc"
170 }
171 }
172 }
Kun Zhang35f77ee2015-06-22 16:29:30 -0700173 }
174
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700175 [
176 compileJava,
177 compileTestJava,
178 compileJmhJava
179 ].each() {
180 // Protobuf-generated code produces some warnings.
181 // https://github.com/google/protobuf/issues/2718
182 it.options.compilerArgs += [
183 "-Xlint:-cast",
184 "-XepExcludedPaths:.*/src/generated/[^/]+/java/.*",
185 ]
Kun Zhang2cdc5e32015-05-11 16:58:28 -0700186 }
Kun Zhang111f6dd2015-05-05 16:11:27 -0700187 }
188
Eric Anderson65d73c02015-05-21 11:54:04 -0700189 def epoll_suffix = "";
190 if (osdetector.classifier in ["linux-x86_64"]) {
191 // The native code is only pre-compiled on certain platforms.
192 epoll_suffix = ":" + osdetector.classifier
193 }
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800194 libraries = [
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700195 errorprone: "com.google.errorprone:error_prone_annotations:2.1.2",
196 gson: "com.google.code.gson:gson:2.7",
197 guava: "com.google.guava:guava:${guavaVersion}",
198 hpack: 'com.twitter:hpack:0.10.1',
199 javax_annotation: 'javax.annotation:javax.annotation-api:1.2',
200 jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
201 oauth_client: 'com.google.auth:google-auth-library-oauth2-http:0.9.0',
202 google_api_protos: 'com.google.api.grpc:proto-google-common-protos:1.0.0',
203 google_auth_credentials: 'com.google.auth:google-auth-library-credentials:0.9.0',
204 okhttp: 'com.squareup.okhttp:okhttp:2.5.0',
205 okio: 'com.squareup.okio:okio:1.13.0',
206 opencensus_api: "io.opencensus:opencensus-api:${opencensusVersion}",
207 opencensus_contrib_grpc_metrics: "io.opencensus:opencensus-contrib-grpc-metrics:${opencensusVersion}",
208 opencensus_impl: "io.opencensus:opencensus-impl:${opencensusVersion}",
209 opencensus_impl_lite: "io.opencensus:opencensus-impl-lite:${opencensusVersion}",
210 instrumentation_api: 'com.google.instrumentation:instrumentation-api:0.4.3',
211 protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
212 protobuf_lite: "com.google.protobuf:protobuf-lite:3.0.1",
213 protoc_lite: "com.google.protobuf:protoc-gen-javalite:3.0.0",
214 protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${protobufNanoVersion}",
215 protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.8.5',
216 protobuf_util: "com.google.protobuf:protobuf-java-util:${protobufVersion}",
217 lang: "org.apache.commons:commons-lang3:3.5",
nathanmittler164b7342014-12-15 09:58:05 -0800218
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700219 netty: "io.netty:netty-codec-http2:[${nettyVersion}]",
220 netty_epoll: "io.netty:netty-transport-native-epoll:${nettyVersion}" + epoll_suffix,
221 netty_proxy_handler: "io.netty:netty-handler-proxy:${nettyVersion}",
222 netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:2.0.8.Final',
nathanmittler164b7342014-12-15 09:58:05 -0800223
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700224 conscrypt: 'org.conscrypt:conscrypt-openjdk-uber:1.0.1',
225 re2j: 'com.google.re2j:re2j:1.2',
Eric Anderson7eab0d92018-02-15 17:14:10 -0800226
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700227 // Test dependencies.
228 junit: 'junit:junit:4.12',
229 mockito: 'org.mockito:mockito-core:1.9.5',
230 truth: 'com.google.truth:truth:0.36',
231 guava_testlib: 'com.google.guava:guava-testlib:20.0',
Louis Ryana7049bc2016-03-23 13:18:04 -0700232
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700233 // Benchmark dependencies
234 hdrhistogram: 'org.hdrhistogram:HdrHistogram:2.1.10',
235 math: 'org.apache.commons:commons-math3:3.6',
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700236
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700237 // Jetty ALPN dependencies
238 jetty_alpn_agent: 'org.mortbay.jetty.alpn:jetty-alpn-agent:2.0.7'
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800239 ]
Jakob Buchgraber7ddcdfd2015-02-13 16:21:53 -0800240 }
nathanmittler164b7342014-12-15 09:58:05 -0800241
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700242 // Define a separate configuration for managing the dependency on Jetty ALPN agent.
nmittler74cfe6c2015-05-22 12:25:10 -0700243 configurations {
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700244 alpnagent
Eric Andersona3ff9cd2017-09-18 16:20:18 -0700245
246 compile {
247 // Detect Maven Enforcer's dependencyConvergence failures. We only
248 // care for artifacts used as libraries by others.
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700249 if (!(project.name in [
250 'grpc-benchmarks',
251 'grpc-interop-testing'
252 ])) {
Eric Andersona3ff9cd2017-09-18 16:20:18 -0700253 resolutionStrategy.failOnVersionConflict()
254 }
255 }
nmittler74cfe6c2015-05-22 12:25:10 -0700256 }
257
nathanmittler164b7342014-12-15 09:58:05 -0800258 dependencies {
259 testCompile libraries.junit,
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700260 libraries.mockito,
261 libraries.truth
nmittler74cfe6c2015-05-22 12:25:10 -0700262
ZHANG Dapengaed886d2016-05-02 14:01:36 -0700263 // Configuration for modules that use Jetty ALPN agent
264 alpnagent libraries.jetty_alpn_agent
Eric Anderson6164b7b2017-08-26 17:10:18 -0700265
266 jmh 'org.openjdk.jmh:jmh-core:1.19',
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700267 'org.openjdk.jmh:jmh-generator-bytecode:1.19'
nathanmittler164b7342014-12-15 09:58:05 -0800268 }
Eric Anderson192144e2015-03-02 13:31:14 -0800269
270 signing {
271 required false
272 sign configurations.archives
273 }
274
nmittler732cfc02015-03-03 07:59:13 -0800275 // Disable JavaDoc doclint on Java 8. It's annoying.
276 if (JavaVersion.current().isJava8Compatible()) {
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700277 allprojects {
278 tasks.withType(Javadoc) {
279 options.addStringOption('Xdoclint:none', '-quiet')
280 }
nmittler732cfc02015-03-03 07:59:13 -0800281 }
nmittler732cfc02015-03-03 07:59:13 -0800282 }
283
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800284 checkstyle {
Eric Andersone6d00622017-07-07 10:57:03 -0700285 configFile = file("$rootDir/buildscripts/checkstyle.xml")
Eric Anderson6ab27ab2016-04-18 09:15:25 -0700286 toolVersion = "6.17"
Eric Andersonad44f0a2015-05-05 08:54:51 -0700287 ignoreFailures = false
Eric Anderson26141b42015-03-21 10:59:17 -0700288 if (rootProject.hasProperty("checkstyle.ignoreFailures")) {
289 ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean()
290 }
Eric Andersonefa774b2015-09-15 10:34:14 -0700291 configProperties["rootDir"] = rootDir
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800292 }
293
294 checkstyleMain {
Kun Zhang693a7d22015-05-06 11:35:08 -0700295 source = fileTree(dir: "src/main", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800296 }
297
298 checkstyleTest {
Kun Zhang693a7d22015-05-06 11:35:08 -0700299 source = fileTree(dir: "src/test", include: "**/*.java")
Eric Andersonc3e8dae2015-01-30 14:58:07 -0800300 }
301
zpencer4f19f142018-03-13 17:46:03 -0700302 // invoke jmh on a single benchmark class like so:
303 // ./gradlew -PjmhIncludeSingleClass=StatsTraceContextBenchmark clean :grpc-core:jmh
Eric Anderson6164b7b2017-08-26 17:10:18 -0700304 jmh {
305 warmupIterations = 10
306 iterations = 10
307 fork = 1
308 // None of our benchmarks need the tests, and we have pseudo-circular
309 // dependencies that break when including them. (context's testCompile
310 // depends on core; core's testCompile depends on testing)
311 includeTests = false
zpencer4f19f142018-03-13 17:46:03 -0700312 if (project.hasProperty('jmhIncludeSingleClass')) {
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700313 include = [
314 project.property('jmhIncludeSingleClass')
315 ]
zpencer4f19f142018-03-13 17:46:03 -0700316 }
Eric Anderson6164b7b2017-08-26 17:10:18 -0700317 }
318
Eric Anderson192144e2015-03-02 13:31:14 -0800319 task javadocJar(type: Jar) {
320 classifier = 'javadoc'
321 from javadoc
322 }
323
324 task sourcesJar(type: Jar) {
325 classifier = 'sources'
326 from sourceSets.main.allSource
327 }
328
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700329 artifacts { archives javadocJar, sourcesJar }
Eric Anderson192144e2015-03-02 13:31:14 -0800330
331 uploadArchives.repositories.mavenDeployer {
332 beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
Eric Anderson4f4cedf2017-12-14 16:51:14 -0800333 if (rootProject.hasProperty('repositoryDir')) {
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700334 repository(url: new File(rootProject.repositoryDir).toURI())
Eric Anderson4f4cedf2017-12-14 16:51:14 -0800335 } else {
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700336 String stagingUrl
337 if (rootProject.hasProperty('repositoryId')) {
338 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' +
339 rootProject.repositoryId
340 } else {
341 stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
zpencer89259212018-02-13 11:17:53 -0800342 }
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700343 def configureAuth = {
344 if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
345 authentication(userName: rootProject.ossrhUsername, password: rootProject.ossrhPassword)
346 }
347 }
348 repository(url: stagingUrl, configureAuth)
349 snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/', configureAuth)
Eric Anderson4f4cedf2017-12-14 16:51:14 -0800350 }
Eric Anderson192144e2015-03-02 13:31:14 -0800351 }
zpencerb07c70a2017-10-06 10:44:58 -0700352 uploadArchives.onlyIf { !name.contains("grpc-gae-interop-testing") }
Eric Anderson192144e2015-03-02 13:31:14 -0800353
354 [
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700355 install.repositories.mavenInstaller,
356 uploadArchives.repositories.mavenDeployer,
Eric Anderson192144e2015-03-02 13:31:14 -0800357 ]*.pom*.whenConfigured { pom ->
358 pom.project {
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700359 name "$project.group:$project.name"
Eric Anderson192144e2015-03-02 13:31:14 -0800360 description project.description
361 url 'https://github.com/grpc/grpc-java'
362
363 scm {
Eric Andersonb7354952016-04-08 08:37:07 -0700364 connection 'scm:git:https://github.com/grpc/grpc-java.git'
365 developerConnection 'scm:git:git@github.com:grpc/grpc-java.git'
Eric Anderson192144e2015-03-02 13:31:14 -0800366 url 'https://github.com/grpc/grpc-java'
367 }
368
369 licenses {
370 license {
Carl Mastrangelo7b97df02017-05-31 14:37:42 -0700371 name 'Apache 2.0'
372 url 'https://opensource.org/licenses/Apache-2.0'
Eric Anderson192144e2015-03-02 13:31:14 -0800373 }
374 }
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700375
376 developers {
377 developer {
378 id "grpc.io"
379 name "gRPC Contributors"
380 email "grpc-io@googlegroups.com"
Mehrdad Afshari8ce0bc22017-07-10 22:48:17 +0000381 url "https://grpc.io/"
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700382 // https://issues.gradle.org/browse/GRADLE-2719
Carl Mastrangelo3bfd6302017-05-31 13:29:01 -0700383 organization = "gRPC Authors"
Eric Anderson7e8a02c2015-03-12 17:03:01 -0700384 organizationUrl "https://www.google.com"
385 }
386 }
Eric Anderson192144e2015-03-02 13:31:14 -0800387 }
Eric Anderson90db93b2016-04-08 13:47:30 -0700388 if (!(project.name in
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700389 [
390 "grpc-stub",
391 "grpc-protobuf",
392 "grpc-protobuf-lite",
393 "grpc-protobuf-nano"
394 ])) {
395 def core = pom.dependencies.find {dep -> dep.artifactId == 'grpc-core'}
396 if (core != null) {
397 // Depend on specific version of grpc-core because internal package is unstable
398 core.version = "[" + core.version + "]"
399 }
Eric Anderson90db93b2016-04-08 13:47:30 -0700400 }
Eric Anderson192144e2015-03-02 13:31:14 -0800401 }
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700402 // At a test failure, log the stack trace to the console so that we don't
403 // have to open the HTML in a browser.
404 test {
405 testLogging {
406 exceptionFormat = 'full'
nmittler4ee2a652015-06-01 16:20:08 -0700407 showExceptions true
408 showCauses true
409 showStackTraces true
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700410 }
Eric Anderson56dca032016-02-12 08:48:41 -0800411 maxHeapSize = '1500m'
Kun Zhang3ddd1d52015-04-22 10:02:19 -0700412 }
nathanmittler164b7342014-12-15 09:58:05 -0800413}
zpencera62108a2017-09-27 08:31:43 -0700414
415// Run with: ./gradlew japicmp --continue
416def baselineGrpcVersion = '1.6.1'
417def publicApiSubprojects = [
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700418 // TODO: uncomment after grpc-alts artifact is published.
419 // ':grpc-alts',
420 ':grpc-auth',
421 ':grpc-context',
422 ':grpc-core',
423 ':grpc-grpclb',
424 ':grpc-netty',
425 ':grpc-okhttp',
426 ':grpc-protobuf',
427 ':grpc-protobuf-lite',
428 ':grpc-protobuf-nano',
429 ':grpc-stub',
430 ':grpc-testing',
zpencera62108a2017-09-27 08:31:43 -0700431]
432
433publicApiSubprojects.each { name ->
434 project(":$name") {
435 apply plugin: 'me.champeau.gradle.japicmp'
436
437 // Get the baseline version's jar for this subproject
438 File baselineArtifact = null
439 // Use a detached configuration, otherwise the current version's jar will take precedence
440 // over the baseline jar.
441 // A necessary hack, the intuitive thing does NOT work:
442 // https://discuss.gradle.org/t/is-the-default-configuration-leaking-into-independent-configurations/2088/6
443 def oldGroup = project.group
444 try {
445 project.group = 'virtual_group_for_japicmp'
446 String depModule = "io.grpc:${project.name}:${baselineGrpcVersion}@jar"
447 String depJar = "${project.name}-${baselineGrpcVersion}.jar"
448 Configuration configuration = configurations.detachedConfiguration(
449 dependencies.create(depModule)
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700450 )
zpencera62108a2017-09-27 08:31:43 -0700451 baselineArtifact = files(configuration.files).filter {
452 it.name.equals(depJar)
453 }.singleFile
454 } finally {
455 project.group = oldGroup
456 }
457
458 // Add a japicmp task that compares the current .jar with baseline .jar
459 task japicmp(type: me.champeau.gradle.japicmp.JapicmpTask, dependsOn: jar) {
460 oldClasspath = files(baselineArtifact)
461 newClasspath = files(jar.archivePath)
462 onlyBinaryIncompatibleModified = false
463 // Be quiet about things that did not change
464 onlyModified = true
465 // This task should fail if there are incompatible changes
466 failOnModification = true
467 ignoreMissingClasses = true
468 htmlOutputFile = file("$buildDir/reports/japi.html")
469
470 packageExcludes = ['io.grpc.internal']
471
472 // Also break on source incompatible changes, not just binary.
473 // Eg adding abstract method to public class.
474 // TODO(zpencer): enable after japicmp-gradle-plugin/pull/14
475 // breakOnSourceIncompatibility = true
476
477 // Ignore any classes or methods marked @ExperimentalApi
478 // TODO(zpencer): enable after japicmp-gradle-plugin/pull/15
479 // annotationExcludes = ['@io.grpc.ExperimentalApi']
480 }
481 }
482}
ZHANG Dapeng5ce10f02018-06-11 18:35:18 -0700483
484// format checkers
485apply plugin: "com.diffplug.gradle.spotless"
486apply plugin: 'groovy'
487spotless {
488 groovyGradle {
489 target '**/*.gradle'
490 greclipse()
491 indentWithSpaces()
492 paddedCell()
493 }
494}