shunping commented on code in PR #38586:
URL: https://github.com/apache/beam/pull/38586#discussion_r3282475407
##########
buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy:
##########
@@ -19,9 +19,39 @@
package org.apache.beam.gradle
import org.gradle.api.Project
+import java.net.HttpURLConnection
+import java.net.URL
class Repositories {
+ private static Boolean isMavenAccessible = null
+
+ static synchronized boolean checkMavenCentral() {
+ if (isMavenAccessible != null) {
+ return isMavenAccessible
+ }
+ def testUrl =
"https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.pom"
+ try {
+ def url = new URL(testUrl)
+ def connection = (HttpURLConnection) url.openConnection()
+ connection.requestMethod = "GET"
+ connection.setRequestProperty("User-Agent", "Gradle")
+ connection.connectTimeout = 2000
+ connection.readTimeout = 2000
+ connection.useCaches = false
+ isMavenAccessible = (connection.responseCode == 200)
+ } catch (Exception e) {
+ isMavenAccessible = false
+ }
+
+ if (isMavenAccessible) {
+ println "Maven Central is accessible. Using default repositories."
+ } else {
+ println "Maven Central is not accessible. Falling back to Google Maven
Mirror."
+ }
+ return isMavenAccessible
+ }
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]