diff --git a/.github/build.gradle b/.github/build.gradle index 6effa8742f60..d5a9a6c9dc75 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 9ad1a6a5bf3b..96b1cb12dd4c 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 12e48356898a..20c878c06a94 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 1d40c7ed4669..95e50105a494 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 9c6bd2b30594..5826665f0a06 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