Skip to content

Commit 6bf1e66

Browse files
committed
Address comments.
1 parent ae94dba commit 6bf1e66

4 files changed

Lines changed: 21 additions & 13 deletions

File tree

buildSrc/build.gradle.kts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
import java.net.HttpURLConnection
1919
import java.net.URL
2020

21-
fun checkMavenCentralAccessibility(): Boolean {
22-
val testUrl = "https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.pom"
21+
fun checkMavenCentralAccessibility(testUrl: String): Boolean {
2322
val accessible = try {
2423
val connection = URL(testUrl).openConnection() as HttpURLConnection
2524
connection.requestMethod = "GET"
@@ -40,8 +39,10 @@ fun checkMavenCentralAccessibility(): Boolean {
4039
return accessible
4140
}
4241

43-
val isMavenAccessible = checkMavenCentralAccessibility()
44-
val mavenCentralMirrorUrl = "https://maven-central.storage-download.googleapis.com/maven2/"
42+
val mavenCentralTestUrl = providers.gradleProperty("mavenCentralTestUrl").getOrElse("https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.pom")
43+
val mavenCentralMirrorUrl = providers.gradleProperty("mavenCentralMirrorUrl").getOrElse("https://maven-central.storage-download.googleapis.com/maven2/")
44+
45+
val isMavenAccessible = checkMavenCentralAccessibility(mavenCentralTestUrl)
4546

4647
// Plugins for configuring _this build_ of the module
4748
plugins {

buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class Repositories {
2626

2727
private static Boolean isMavenAccessible = null
2828

29-
static synchronized boolean checkMavenCentral() {
29+
static synchronized boolean checkMavenCentral(Project project) {
3030
if (isMavenAccessible != null) {
3131
return isMavenAccessible
3232
}
33-
def testUrl = "https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.pom"
33+
def testUrl = project.findProperty("mavenCentralTestUrl") ?: "https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.pom"
3434
try {
3535
def url = new URL(testUrl)
3636
def connection = (HttpURLConnection) url.openConnection()
@@ -47,12 +47,13 @@ class Repositories {
4747
if (isMavenAccessible) {
4848
println "Maven Central is accessible. Using default repositories."
4949
} else {
50-
println "Maven Central is not accessible. Falling back to Google Maven Mirror."
50+
println "Maven Central is not accessible. Redirecting to Google Maven Mirror."
5151
}
5252
return isMavenAccessible
5353
}
5454

5555
static void register(Project project) {
56+
def mirrorUrl = project.findProperty("mavenCentralMirrorUrl") ?: "https://maven-central.storage-download.googleapis.com/maven2/"
5657

5758
project.repositories {
5859
maven { url project.offlineRepositoryRoot }
@@ -66,10 +67,10 @@ class Repositories {
6667
return
6768
}
6869

69-
if (checkMavenCentral()) {
70+
if (checkMavenCentral(project)) {
7071
mavenCentral()
7172
} else {
72-
maven { url "https://maven-central.storage-download.googleapis.com/maven2/" }
73+
maven { url mirrorUrl }
7374
}
7475
mavenLocal()
7576

@@ -102,10 +103,10 @@ class Repositories {
102103
project.offlineDependencies {
103104
repositories {
104105
mavenLocal()
105-
if (checkMavenCentral()) {
106+
if (checkMavenCentral(project)) {
106107
mavenCentral()
107108
} else {
108-
maven { url "https://maven-central.storage-download.googleapis.com/maven2/" }
109+
maven { url mirrorUrl }
109110
}
110111
maven { url "https://plugins.gradle.org/m2/" }
111112
maven { url "https://repo.spring.io/plugins-release" }

gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ flink_versions=1.17,1.18,1.19,1.20,2.0
4444
spark_versions=3,4
4545
# supported python versions
4646
python_versions=3.10,3.11,3.12,3.13,3.14
47+
48+
# Maven Central fallback mirror and connectivity test URL
49+
mavenCentralMirrorUrl=https://maven-central.storage-download.googleapis.com/maven2/
50+
mavenCentralTestUrl=https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.pom

settings.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
import com.gradle.enterprise.gradleplugin.internal.extension.BuildScanExtensionWithHiddenFeatures
1919

2020
pluginManagement {
21+
val mavenCentralTestUrl = settings.providers.gradleProperty("mavenCentralTestUrl").getOrElse("https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.pom")
22+
val mavenCentralMirrorUrl = settings.providers.gradleProperty("mavenCentralMirrorUrl").getOrElse("https://maven-central.storage-download.googleapis.com/maven2/")
23+
2124
val isMavenAccessible = try {
22-
val connection = java.net.URL("https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.pom").openConnection() as java.net.HttpURLConnection
25+
val connection = java.net.URL(mavenCentralTestUrl).openConnection() as java.net.HttpURLConnection
2326
connection.requestMethod = "GET"
2427
connection.setRequestProperty("User-Agent", "Gradle")
2528
connection.connectTimeout = 2000
@@ -29,7 +32,6 @@ pluginManagement {
2932
} catch (e: Exception) {
3033
false
3134
}
32-
val mavenCentralMirrorUrl = "https://maven-central.storage-download.googleapis.com/maven2/"
3335

3436
if (isMavenAccessible) {
3537
logger.lifecycle("Maven Central is accessible. Using default repositories for settings plugins.")

0 commit comments

Comments
 (0)