Skip to content

Commit ce9d217

Browse files
authored
all: introduce gradle util functions to manage guava dependency
Define util function to exclude guava's transitive dependencies jsr305 and animal-sniffer-annotations, and always manually add them as runtimeOnly dependency. error_prone_annotations is an exception: It is also excluded but manually added not as runtimeOnly. It must always compile with guava, otherwise users will see warning spams if guava is in the compile classpath but error_prone_annotations is not.
1 parent 9520dc4 commit ce9d217

File tree

7 files changed

+59
-48
lines changed

7 files changed

+59
-48
lines changed

api/build.gradle

+1-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ dependencies {
1515
libraries.errorprone,
1616
libraries.jsr305,
1717
libraries.animalsniffer_annotations
18-
compile (libraries.guava) {
19-
// prefer our own versions from libraries instead of Guava's dependency
20-
exclude group: 'com.google.errorprone', module: 'error_prone_annotations'
21-
exclude group: 'com.google.code.findbugs', module: 'jsr305'
22-
exclude group: 'org.codehaus.mojo', module: 'animal-sniffer-annotations'
23-
}
18+
guavaDependency 'compile'
2419

2520
testCompile project(':grpc-context').sourceSets.test.output,
2621
project(':grpc-testing'),

build.gradle

+51
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,57 @@ subprojects {
187187
// Jetty ALPN dependencies
188188
jetty_alpn_agent: 'org.mortbay.jetty.alpn:jetty-alpn-agent:2.0.9'
189189
]
190+
191+
// A util function to config guava dependency with transitive dependencies
192+
// properly resolved for the failOnVersionConflict strategy.
193+
guavaDependency = { configurationName ->
194+
dependencies."$configurationName"(libraries.guava) {
195+
exclude group: 'com.google.code.findbugs', module: 'jsr305'
196+
exclude group: 'com.google.errorprone', module: 'error_prone_annotations'
197+
exclude group: 'org.codehaus.mojo', module: 'animal-sniffer-annotations'
198+
}
199+
dependencies."$configurationName" libraries.errorprone
200+
dependencies.runtimeOnly libraries.animalsniffer_annotations
201+
dependencies.runtimeOnly libraries.jsr305
202+
}
203+
204+
// A util function to config opencensus_api dependency with transitive
205+
// dependencies properly resolved for the failOnVersionConflict strategy.
206+
censusApiDependency = { configurationName ->
207+
dependencies."$configurationName"(libraries.opencensus_api) {
208+
exclude group: 'com.google.code.findbugs', module: 'jsr305'
209+
exclude group: 'com.google.guava', module: 'guava'
210+
// we'll always be more up-to-date
211+
exclude group: 'io.grpc', module: 'grpc-context'
212+
}
213+
dependencies.runtimeOnly project(':grpc-context')
214+
dependencies.runtimeOnly libraries.jsr305
215+
guavaDependency 'runtimeOnly'
216+
}
217+
218+
// A util function to config opencensus_contrib_grpc_metrics dependency
219+
// with transitive dependencies properly resolved for the failOnVersionConflict
220+
// strategy.
221+
censusGrpcMetricDependency = { configurationName ->
222+
dependencies."$configurationName"(libraries.opencensus_contrib_grpc_metrics) {
223+
exclude group: 'com.google.code.findbugs', module: 'jsr305'
224+
exclude group: 'com.google.guava', module: 'guava'
225+
// we'll always be more up-to-date
226+
exclude group: 'io.grpc', module: 'grpc-context'
227+
}
228+
dependencies.runtimeOnly project(':grpc-context')
229+
dependencies.runtimeOnly libraries.jsr305
230+
guavaDependency 'runtimeOnly'
231+
}
232+
233+
// A util function to config perfmark dependency with transitive
234+
// dependencies properly resolved for the failOnVersionConflict strategy.
235+
perfmarkDependency = { configurationName ->
236+
dependencies."$configurationName"(libraries.perfmark) {
237+
exclude group: 'com.google.errorprone', module: 'error_prone_annotations'
238+
}
239+
dependencies.runtimeOnly libraries.errorprone
240+
}
190241
}
191242

192243
configurations {

census/build.gradle

+3-18
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,9 @@ evaluationDependsOn(project(':grpc-api').path)
99

1010
dependencies {
1111
compile project(':grpc-api')
12-
13-
compile (libraries.opencensus_api) {
14-
// prefer 3.0.2 from libraries instead of 3.0.1
15-
exclude group: 'com.google.code.findbugs', module: 'jsr305'
16-
// prefer 20.0 from libraries instead of 19.0
17-
exclude group: 'com.google.guava', module: 'guava'
18-
// we'll always be more up-to-date
19-
exclude group: 'io.grpc', module: 'grpc-context'
20-
}
21-
22-
compile (libraries.opencensus_contrib_grpc_metrics) {
23-
// prefer 3.0.2 from libraries instead of 3.0.1
24-
exclude group: 'com.google.code.findbugs', module: 'jsr305'
25-
// we'll always be more up-to-date
26-
exclude group: 'io.grpc', module: 'grpc-context'
27-
// prefer 20.0 from libraries instead of 19.0
28-
exclude group: 'com.google.guava', module: 'guava'
29-
}
12+
13+
censusApiDependency 'compile'
14+
censusGrpcMetricDependency 'compile'
3015

3116
testCompile project(':grpc-api').sourceSets.test.output,
3217
project(':grpc-context').sourceSets.test.output,

core/build.gradle

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ dependencies {
1717
libraries.gson,
1818
libraries.android_annotations,
1919
libraries.errorprone // prefer our version to perfmark's 2.3.3
20-
compile (libraries.perfmark) {
21-
exclude group: 'com.google.errorprone', module: 'error_prone_annotations'
22-
}
23-
20+
perfmarkDependency 'compile'
2421
testCompile project(':grpc-context').sourceSets.test.output,
2522
project(':grpc-api').sourceSets.test.output,
2623
project(':grpc-testing'),

protobuf-lite/build.gradle

+1-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ description = 'gRPC: Protobuf Lite'
1212
dependencies {
1313
compile project(':grpc-api'),
1414
libraries.protobuf_lite
15-
compile (libraries.guava) {
16-
// prefer our own versions from libraries instead of Guava's dependency
17-
exclude group: 'com.google.errorprone', module: 'error_prone_annotations'
18-
exclude group: 'com.google.code.findbugs', module: 'jsr305'
19-
exclude group: 'org.codehaus.mojo', module: 'animal-sniffer-annotations'
20-
}
15+
guavaDependency 'compile'
2116

2217
testCompile project(':grpc-core')
2318

protobuf/build.gradle

+1-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ description = 'gRPC: Protobuf'
1212
dependencies {
1313
compile project(':grpc-api'),
1414
libraries.protobuf
15-
compile (libraries.guava) {
16-
// prefer our own versions from libraries instead of Guava's dependency
17-
exclude group: 'com.google.errorprone', module: 'error_prone_annotations'
18-
exclude group: 'com.google.code.findbugs', module: 'jsr305'
19-
exclude group: 'org.codehaus.mojo', module: 'animal-sniffer-annotations'
20-
}
15+
guavaDependency 'compile'
2116

2217
compile (libraries.google_api_protos) {
2318
// 'com.google.api:api-common' transitively depends on auto-value, which breaks our

testing/build.gradle

+1-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ dependencies {
1414
project(':grpc-stub'),
1515
libraries.junit
1616

17-
compile (libraries.opencensus_api) {
18-
// prefer 3.0.2 from libraries instead of 3.0.1
19-
exclude group: 'com.google.code.findbugs', module: 'jsr305'
20-
// prefer 20.0 from libraries instead of 19.0
21-
exclude group: 'com.google.guava', module: 'guava'
22-
// we'll always be more up-to-date
23-
exclude group: 'io.grpc', module: 'grpc-context'
24-
}
17+
censusApiDependency 'compile'
2518

2619
testCompile (libraries.mockito) {
2720
// prefer our own versions instead of mockito's dependency

0 commit comments

Comments
 (0)