From 518f6cf96af07647b39ca8d183a4fdbb6eeaa4b4 Mon Sep 17 00:00:00 2001
From: Eric Anderson <ejona@google.com>
Date: Fri, 27 Dec 2024 12:04:58 -0800
Subject: [PATCH] Disable Gradle Module Metadata resolution

The module metadata in Guava causes the -jre version to be selected even
when you choose the -android version. Gradle did not give any clues that
this was happening, and while
`println(configurations.compileClasspath.resolve())` shows the different
jar in use, most other diagonstics don't. dependencyInsight can show you
this is happening, but only if you know which dependency has a problem
and read Guava's module metadata first to understand the significance of
the results.

You could argue this is a Guava-specific problem. I was able to get
parts of our build working with attributes and resolutionStrategy
configurations mentioned at
https://github.com/google/guava/releases/tag/v32.1.0 , so that only
Guava would be changed. But it was fickle giving poor error messages or
silently swapping back to the -jre version.

Given the weak debuggability, the added complexity, and the lack of
value module metadata is providing us, disabling module metadata for our
entire build seems prudent.

See https://github.com/google/guava/issues/7575
---
 android-interop-testing/build.gradle |  1 -
 android/build.gradle                 |  1 -
 binder/build.gradle                  |  1 -
 build.gradle                         | 21 ++++++++++++++++++---
 cronet/build.gradle                  |  1 -
 gradle/libs.versions.toml            |  2 +-
 6 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/android-interop-testing/build.gradle b/android-interop-testing/build.gradle
index 9b3b021afce..1d39aee1750 100644
--- a/android-interop-testing/build.gradle
+++ b/android-interop-testing/build.gradle
@@ -7,7 +7,6 @@ description = 'gRPC: Android Integration Testing'
 
 repositories {
     google()
-    mavenCentral()
 }
 
 android {
diff --git a/android/build.gradle b/android/build.gradle
index 3b3bfa59b96..3c717da18a3 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -31,7 +31,6 @@ android {
 
 repositories {
     google()
-    mavenCentral()
 }
 
 dependencies {
diff --git a/binder/build.gradle b/binder/build.gradle
index e18361e08b3..3390e02fce7 100644
--- a/binder/build.gradle
+++ b/binder/build.gradle
@@ -32,7 +32,6 @@ android {
 
 repositories {
     google()
-    mavenCentral()
 }
 
 dependencies {
diff --git a/build.gradle b/build.gradle
index 52ca19ab4ba..39d2b6ad289 100644
--- a/build.gradle
+++ b/build.gradle
@@ -25,9 +25,24 @@ subprojects {
 
     repositories {
         maven { // The google mirror is less flaky than mavenCentral()
-            url "https://maven-central.storage-download.googleapis.com/maven2/" }
-        mavenCentral()
-        mavenLocal()
+            url "https://maven-central.storage-download.googleapis.com/maven2/"
+            metadataSources {
+                mavenPom()
+                ignoreGradleMetadataRedirection()
+            }
+        }
+        mavenCentral() {
+            metadataSources {
+                mavenPom()
+                ignoreGradleMetadataRedirection()
+            }
+        }
+        mavenLocal() {
+            metadataSources {
+                mavenPom()
+                ignoreGradleMetadataRedirection()
+            }
+        }
     }
 
     tasks.withType(JavaCompile).configureEach {
diff --git a/cronet/build.gradle b/cronet/build.gradle
index 3252a9d249b..1a327f9f966 100644
--- a/cronet/build.gradle
+++ b/cronet/build.gradle
@@ -8,7 +8,6 @@ description = "gRPC: Cronet Android"
 
 repositories {
     google()
-    mavenCentral()
 }
 
 android {
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 4d871239cc2..43ec3368b76 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -62,7 +62,7 @@ jetty-servlet10 = "org.eclipse.jetty:jetty-servlet:10.0.20"
 jsr305 = "com.google.code.findbugs:jsr305:3.0.2"
 junit = "junit:junit:4.13.2"
 # 2.17+ require Java 11+ (not mentioned in release notes)
-lincheck = "org.jetbrains.kotlinx:lincheck:2.16"
+lincheck = "org.jetbrains.kotlinx:lincheck-jvm:2.16"
 # Update notes / 2023-07-19 sergiitk:
 #    Couldn't update to 5.4.0, updated to the last in 4.x line. Version 5.x breaks some tests.
 #    Error log: https://github.com/grpc/grpc-java/pull/10359#issuecomment-1632834435