This is an automated email from the ASF dual-hosted git repository.

shunping pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 60620e788f0 Enforce Google Maven Mirror on CI environments (#38586)
60620e788f0 is described below

commit 60620e788f08ffdb94d90e5568886608dd211bc9
Author: Shunping Huang <[email protected]>
AuthorDate: Thu May 21 14:06:02 2026 -0400

    Enforce Google Maven Mirror on CI environments (#38586)
    
    * Implement Maven Central mirroring in CI environments
    
    * Fix subproject buildscript classpath resolution for beam-test-gha using 
CI mirror fallback
    
    * Remove duplicated definition.
    
    * Discard the new settings file in buildSrc first.
    
    * Fix compilation error.
---
 .github/build.gradle                               | 10 +++++++++-
 buildSrc/build.gradle.kts                          | 19 +++++++++++++++++++
 .../org/apache/beam/gradle/Repositories.groovy     | 22 ++++++++++++++++++----
 gradle.properties                                  |  3 +++
 settings.gradle.kts                                | 15 ++++++++++++++-
 5 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/.github/build.gradle b/.github/build.gradle
index 6effa8742f6..d5a9a6c9dc7 100644
--- a/.github/build.gradle
+++ b/.github/build.gradle
@@ -18,7 +18,15 @@
 
 buildscript {
   repositories {
-    mavenCentral()
+    def mirrorUrl = project.findProperty("mavenCentralMirrorUrl")
+    boolean isCi = System.getenv("GITHUB_ACTIONS") != null || 
System.getenv("JENKINS_HOME") != null
+    def useMirror = isCi && mirrorUrl
+
+    if (!useMirror) {
+      mavenCentral()
+    } else {
+      maven { url mirrorUrl }
+    }
   }
   dependencies {
     classpath group: 'org.yaml', name: 'snakeyaml', version: '2.2'
diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts
index 9ad1a6a5bf3..96b1cb12dd4 100644
--- a/buildSrc/build.gradle.kts
+++ b/buildSrc/build.gradle.kts
@@ -15,6 +15,18 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+import java.util.Properties
+
+val parentProperties = Properties().apply {
+  val file = file("../gradle.properties")
+  if (file.exists()) {
+    file.inputStream().use { load(it) }
+  }
+}
+
+val mavenCentralMirrorUrl = 
parentProperties.getProperty("mavenCentralMirrorUrl")
+val isCi = System.getenv("GITHUB_ACTIONS") != null || 
System.getenv("JENKINS_HOME") != null
+val useMirror = isCi && !mavenCentralMirrorUrl.isNullOrBlank()
 
 // Plugins for configuring _this build_ of the module
 plugins {
@@ -25,6 +37,13 @@ plugins {
 
 // Define the set of repositories required to fetch and enable plugins.
 repositories {
+  if (useMirror) {
+    logger.lifecycle("Running in CI. Mirroring Maven Central repositories via 
Google Maven Mirror for buildSrc.")
+  }
+
+  if (useMirror) {
+    maven { url = uri(mavenCentralMirrorUrl!!) }
+  }
   maven { url = uri("https://plugins.gradle.org/m2/";) }
   maven {
     url = uri("https://repo.spring.io/plugins-release/";)
diff --git 
a/buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy 
b/buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy
index 12e48356898..20c878c06a9 100644
--- a/buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy
+++ b/buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy
@@ -19,10 +19,16 @@
 package org.apache.beam.gradle
 
 import org.gradle.api.Project
-
 class Repositories {
 
   static void register(Project project) {
+    def mirrorUrl = project.findProperty("mavenCentralMirrorUrl")
+    boolean isCi = System.getenv("GITHUB_ACTIONS") != null || 
System.getenv("JENKINS_HOME") != null
+    def useMirror = isCi && mirrorUrl
+
+    if (useMirror) {
+      project.logger.lifecycle("Running in CI. Mirroring Maven Central 
repositories via Google Maven Mirror.")
+    }
 
     project.repositories {
       maven { url project.offlineRepositoryRoot }
@@ -36,7 +42,11 @@ class Repositories {
         return
       }
 
-      mavenCentral()
+      if (!useMirror) {
+        mavenCentral()
+      } else {
+        maven { url mirrorUrl }
+      }
       mavenLocal()
 
       // For Confluent Kafka dependencies
@@ -60,7 +70,7 @@ class Repositories {
     // Apply a plugin which provides the 'updateOfflineRepository' task that 
creates an offline
     // repository. This offline repository satisfies all Gradle build 
dependencies and Java
     // project dependencies. The offline repository is placed within 
$rootDir/offline-repo
-    // but can be overridden by specifying 
'-PofflineRepositoryRoot=/path/to/repo'.
+    // but can be overridden by specifying '-Pareas/offline-repo'.
     // Note that parallel build must be disabled when executing 
'updateOfflineRepository'
     // by specifying '--no-parallel', see
     // 
https://github.com/mdietrichstein/gradle-offline-dependencies-plugin/issues/3
@@ -68,7 +78,11 @@ class Repositories {
     project.offlineDependencies {
       repositories {
         mavenLocal()
-        mavenCentral()
+        if (!useMirror) {
+          mavenCentral()
+        } else {
+          maven { url mirrorUrl }
+        }
         maven { url "https://plugins.gradle.org/m2/"; }
         maven { url "https://repo.spring.io/plugins-release"; }
         maven { url "https://packages.confluent.io/maven/"; }
diff --git a/gradle.properties b/gradle.properties
index 1d40c7ed466..95e50105a49 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -44,3 +44,6 @@ flink_versions=1.17,1.18,1.19,1.20,2.0
 spark_versions=3,4
 # supported python versions
 python_versions=3.10,3.11,3.12,3.13,3.14
+
+# Maven Central fallback mirror URL
+mavenCentralMirrorUrl=https://maven-central.storage-download.googleapis.com/maven2/
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 1ead92a9cfc..603832045f3 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -18,6 +18,20 @@
 import 
com.gradle.enterprise.gradleplugin.internal.extension.BuildScanExtensionWithHiddenFeatures
 
 pluginManagement {
+    val mavenCentralMirrorUrl = 
settings.providers.gradleProperty("mavenCentralMirrorUrl").orNull
+    val isCi = System.getenv("GITHUB_ACTIONS") != null || 
System.getenv("JENKINS_HOME") != null
+    val useMirror = isCi && !mavenCentralMirrorUrl.isNullOrBlank()
+
+    if (useMirror) {
+        logger.lifecycle("Running in CI. Mirroring Maven Central repositories 
via Google Maven Mirror.")
+    }
+
+    repositories {
+        if (useMirror) {
+            maven { url = uri(mavenCentralMirrorUrl!!) }
+        }
+        gradlePluginPortal()
+    }
     plugins {
         id("org.javacc.javacc") version "4.0.3" // enable the JavaCC parser 
generator
     }
@@ -28,7 +42,6 @@ plugins {
     id("com.gradle.common-custom-user-data-gradle-plugin") version "2.6.0"
 }
 
-
 // JENKINS_HOME and BUILD_ID set automatically during Jenkins execution
 val isJenkinsBuild = arrayOf("JENKINS_HOME", "BUILD_ID").all { 
System.getenv(it) != null }
 // GITHUB_REPOSITORY and GITHUB_RUN_ID set automatically during Github Actions 
run

Reply via email to