From f1360285d6ae42080339d1dbe0376b33f0492dcd Mon Sep 17 00:00:00 2001 From: Weimin Yu Date: Mon, 16 Sep 2019 14:36:14 -0400 Subject: [PATCH] Force Gradle to use jre version of Guava (#271) * Force Gradle to use jre version of Guava Guava is often specified by version only by other dependencies. In such cases, Gradle usually resolves it to the '-android' version, which lacks the collection classes. We use custom resolution strategy to force the selection of the '-jre' version. --- java_common.gradle | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/java_common.gradle b/java_common.gradle index 16430215a..fe1c41232 100644 --- a/java_common.gradle +++ b/java_common.gradle @@ -28,6 +28,20 @@ tasks.test.dependsOn tasks.checkstyleTest // TODO(weiminyu): investigate incremental coverage change calculation and alert. tasks.test.finalizedBy jacocoTestReport +configurations.all { + // Guava as a transitive dependency is also referred to by version only, + // without suffix. In such cases, Gradle resolves it to ${version}-android, + // which lacks the collection classes. We use custom strategy to force the + // selection of '-jre' jar. + resolutionStrategy.eachDependency { DependencyResolveDetails details -> + if (details.requested.group == 'com.google.guava' + && details.requested.name == 'guava' + && details.requested.version.endsWith('-android')) { + details.useVersion details.requested.version.replace('-android', '-jre') + } + } +} + dependencies { // compatibility with Java 8 errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")