You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "shunping (via GitHub)" <gi...@apache.org> on 2026/05/21 14:08:26 UTC
[PR] Attempt to fix recent hiccup of official maven repo [beam]
shunping opened a new pull request, #38586:
URL: https://github.com/apache/beam/pull/38586
**Please** add a meaningful description for your change here
------------------------
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
- [ ] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fallback to Google Maven Mirror on Maven Central block/throttle [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #38586:
URL: https://github.com/apache/beam/pull/38586#issuecomment-4509516986
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment `assign set of reviewers`
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce Google Maven Mirror on CI environments [beam]
Posted by "shunping (via GitHub)" <gi...@apache.org>.
shunping commented on code in PR #38586:
URL: https://github.com/apache/beam/pull/38586#discussion_r3283099482
##########
settings.gradle.kts:
##########
@@ -18,6 +18,20 @@
import com.gradle.enterprise.gradleplugin.internal.extension.BuildScanExtensionWithHiddenFeatures
pluginManagement {
+ val mavenCentralMirrorUrl = settings.providers.gradleProperty("mavenCentralMirrorUrl").orNull
Review Comment:
I have to keep the isCi in `pluginManagement`, because it is evaluated before the other statements. Otherwise I will get
```
Script compilation error:
Line 28: val useMirror = isCi && !mavenCentralMirrorUrl.isNullOrBlank()
^ Unresolved reference: isCi
1 error
```
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce Google Maven Mirror on CI environments [beam]
Posted by "shunping (via GitHub)" <gi...@apache.org>.
shunping merged PR #38586:
URL: https://github.com/apache/beam/pull/38586
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce Google Maven Mirror on CI environments [beam]
Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn commented on code in PR #38586:
URL: https://github.com/apache/beam/pull/38586#discussion_r3282928295
##########
settings.gradle.kts:
##########
@@ -18,6 +18,20 @@
import com.gradle.enterprise.gradleplugin.internal.extension.BuildScanExtensionWithHiddenFeatures
pluginManagement {
+ val mavenCentralMirrorUrl = settings.providers.gradleProperty("mavenCentralMirrorUrl").orNull
Review Comment:
This largely duplicates "val isCi" in L50
##########
buildSrc/settings.gradle.kts:
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Properties
+
+pluginManagement {
Review Comment:
We can check settings.gradle.kts and Repository.groovy changes first then the traffic to maven central should largely diminished, then this settings is no longer needed.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce Google Maven Mirror on CI environments [beam]
Posted by "shunping (via GitHub)" <gi...@apache.org>.
shunping commented on code in PR #38586:
URL: https://github.com/apache/beam/pull/38586#discussion_r3283108932
##########
buildSrc/settings.gradle.kts:
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Properties
+
+pluginManagement {
Review Comment:
Ok. We can try this.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce Google Maven Mirror on CI environments [beam]
Posted by "shunping (via GitHub)" <gi...@apache.org>.
shunping commented on code in PR #38586:
URL: https://github.com/apache/beam/pull/38586#discussion_r3283348399
##########
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.")
Review Comment:
Let's keep them for now. We can remove them later if the infra problem is resolved.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fallback to Google Maven Mirror on Maven Central block/throttle [beam]
Posted by "shunping (via GitHub)" <gi...@apache.org>.
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fallback to Google Maven Mirror on Maven Central block/throttle [beam]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #38586:
URL: https://github.com/apache/beam/pull/38586#issuecomment-4509536581
## Summary of Changes
Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a robust fallback mechanism for dependency resolution in the build process. By dynamically verifying connectivity to Maven Central, the build system can now automatically switch to the Google Maven Mirror if it detects throttling or blocking, preventing build failures caused by network restrictions on shared CI runners.
### Highlights
* **Resilience to Maven Central Throttling**: Implemented a runtime connectivity check to Maven Central across build scripts and settings to detect 403 Forbidden or connection errors.
* **Automatic Fallback Mechanism**: Introduced a fallback to the Google Maven Mirror when Maven Central is unreachable, ensuring build stability on restricted environments like GitHub Actions runners.
<details>
<summary><b>New Features</b></summary>
đź§ You can now enable **Memory** (public preview) to help **Gemini Code Assist** learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. **Click [here](https://codeassist.google/code-review/login) to enable Memory in your admin console.**
</details>
<details>
<summary><b>Using Gemini Code Assist</b></summary>
<br>
The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
<b>Invoking Gemini</b>
You can request assistance from Gemini at any point by creating a comment using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands on the current page.
Feature | Command | Description
--- | --- | ---
Code Review | `/gemini review` | Performs a code review for the current pull request in its current state.
Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state.
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help | `/gemini help` | Displays a list of available commands.
<b>Customization</b>
To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
<b>Limitations & Feedback</b>
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up [here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
</details>
[^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fallback to Google Maven Mirror on Maven Central block/throttle [beam]
Posted by "shunping (via GitHub)" <gi...@apache.org>.
shunping commented on code in PR #38586:
URL: https://github.com/apache/beam/pull/38586#discussion_r3282285208
##########
buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy:
##########
@@ -68,8 +102,12 @@ class Repositories {
project.offlineDependencies {
repositories {
mavenLocal()
- mavenCentral()
- maven { url "https://plugins.gradle.org/m2/" }
+ if (checkMavenCentral()) {
+ mavenCentral()
+ maven { url "https://plugins.gradle.org/m2/" }
+ } else {
+ maven { url "https://maven-central.storage-download.googleapis.com/maven2/" }
+ }
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Enforce Google Maven Mirror on CI environments [beam]
Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn commented on code in PR #38586:
URL: https://github.com/apache/beam/pull/38586#discussion_r3283312955
##########
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.")
Review Comment:
This log appears multiple times. Logging here once should suffice
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fallback to Google Maven Mirror on Maven Central block/throttle [beam]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #38586:
URL: https://github.com/apache/beam/pull/38586#discussion_r3282185748
##########
settings.gradle.kts:
##########
@@ -18,6 +18,33 @@
import com.gradle.enterprise.gradleplugin.internal.extension.BuildScanExtensionWithHiddenFeatures
pluginManagement {
+ val isMavenAccessible = try {
+ 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
+ connection.requestMethod = "GET"
+ connection.setRequestProperty("User-Agent", "Gradle")
+ connection.connectTimeout = 2000
+ connection.readTimeout = 2000
+ connection.useCaches = false
+ connection.responseCode == 200
+ } catch (e: Exception) {
+ false
+ }
+ val mavenCentralMirrorUrl = "https://maven-central.storage-download.googleapis.com/maven2/"
+
+ if (isMavenAccessible) {
+ logger.lifecycle("Maven Central is accessible. Using default repositories for settings plugins.")
+ } else {
+ logger.lifecycle("Maven Central is not accessible. Falling back to Google Maven Mirror for settings plugins.")
+ }
+
+ repositories {
+ if (isMavenAccessible) {
+ gradlePluginPortal()
+ } else {
+ maven { url = uri(mavenCentralMirrorUrl) }
+ gradlePluginPortal()
+ }
Review Comment:

The `gradlePluginPortal()` call is duplicated in both branches of the accessibility check. Moving it outside the conditional block makes the logic cleaner and easier to maintain.
```kotlin
if (!isMavenAccessible) {
maven { url = uri(mavenCentralMirrorUrl) }
}
gradlePluginPortal()
```
##########
buildSrc/build.gradle.kts:
##########
@@ -25,7 +52,12 @@ plugins {
// Define the set of repositories required to fetch and enable plugins.
repositories {
- maven { url = uri("https://plugins.gradle.org/m2/") }
+ if (isMavenAccessible) {
+ maven { url = uri("https://plugins.gradle.org/m2/") }
+ } else {
+ maven { url = uri(mavenCentralMirrorUrl) }
+ maven { url = uri("https://plugins.gradle.org/m2/") }
+ }
Review Comment:

The declaration of the Gradle Plugin Portal repository is duplicated in both branches of the conditional. This can be simplified by moving the common repository outside the `if` block, improving maintainability.
```kotlin
if (!isMavenAccessible) {
maven { url = uri(mavenCentralMirrorUrl) }
}
maven { url = uri("https://plugins.gradle.org/m2/") }
```
##########
buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy:
##########
@@ -68,8 +102,12 @@ class Repositories {
project.offlineDependencies {
repositories {
mavenLocal()
- mavenCentral()
- maven { url "https://plugins.gradle.org/m2/" }
+ if (checkMavenCentral()) {
+ mavenCentral()
+ maven { url "https://plugins.gradle.org/m2/" }
+ } else {
+ maven { url "https://maven-central.storage-download.googleapis.com/maven2/" }
+ }
Review Comment:

The current logic in the `offlineDependencies` block excludes the Gradle Plugin Portal repository when Maven Central is inaccessible. Since the Google Maven Mirror only mirrors Maven Central, any dependencies that are exclusively hosted on the Gradle Plugin Portal will fail to resolve in this scenario. The Plugin Portal should be included regardless of Maven Central's accessibility.
```
if (checkMavenCentral()) {
mavenCentral()
} else {
maven { url "https://maven-central.storage-download.googleapis.com/maven2/" }
}
maven { url "https://plugins.gradle.org/m2/" }
```
##########
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:

The logic for checking Maven Central accessibility and the associated URLs are duplicated across `build.gradle.kts`, `Repositories.groovy`, and `settings.gradle.kts`. While some duplication is expected due to the Gradle lifecycle (e.g., `settings.gradle.kts` running before `buildSrc` is available), the duplication within `buildSrc` itself could be reduced. Consider centralizing the test URL and the mirror URL into a shared configuration or at least using constants to avoid potential inconsistencies in the future.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fallback to Google Maven Mirror on Maven Central block/throttle [beam]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #38586:
URL: https://github.com/apache/beam/pull/38586#discussion_r3282670233
##########
buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy:
##########
@@ -19,10 +19,51 @@
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(Project project) {
+ if (isMavenAccessible != null) {
+ return isMavenAccessible
+ }
Review Comment:

To avoid redundant network checks, consider reusing the result of the connectivity test performed during the `buildSrc` initialization phase, which is stored in the `buildSrc.maven.accessible` system property.
```
if (isMavenAccessible != null) {
return isMavenAccessible
}
def cached = System.getProperty("buildSrc.maven.accessible")
if (cached != null) {
isMavenAccessible = Boolean.valueOf(cached)
return isMavenAccessible
}
```
##########
buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy:
##########
@@ -19,10 +19,51 @@
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(Project project) {
+ if (isMavenAccessible != null) {
+ return isMavenAccessible
+ }
+ def testUrl = project.findProperty("mavenCentralTestUrl")
+ if (!testUrl) {
+ isMavenAccessible = true
+ return isMavenAccessible
+ }
+ 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
+ }
+
+ def mirrorUrl = project.findProperty("mavenCentralMirrorUrl")
+ def useFallback = !isMavenAccessible && mirrorUrl
+
+ if (isMavenAccessible) {
+ println "Maven Central is accessible. Using default repositories."
+ } else if (useFallback) {
+ println "Maven Central is not accessible. Redirecting to Google Maven Mirror."
+ } else {
+ println "Maven Central is not accessible and no mirror is configured. Using default repositories."
+ }
Review Comment:

Use `project.logger.lifecycle` instead of `println` for better integration with Gradle's logging system.
```
if (isMavenAccessible) {
project.logger.lifecycle "Maven Central is accessible. Using default repositories."
} else if (useFallback) {
project.logger.lifecycle "Maven Central is not accessible. Redirecting to Google Maven Mirror."
} else {
project.logger.lifecycle "Maven Central is not accessible and no mirror is configured. Using default repositories."
}
```
##########
settings.gradle.kts:
##########
@@ -18,6 +18,41 @@
import com.gradle.enterprise.gradleplugin.internal.extension.BuildScanExtensionWithHiddenFeatures
pluginManagement {
+ val mavenCentralTestUrl = settings.providers.gradleProperty("mavenCentralTestUrl").orNull
+ val mavenCentralMirrorUrl = settings.providers.gradleProperty("mavenCentralMirrorUrl").orNull
+
+ val isMavenAccessible = if (!mavenCentralTestUrl.isNullOrBlank()) {
Review Comment:

To avoid redundant network checks, consider reusing the result of the connectivity test performed during the `buildSrc` initialization phase.
```kotlin
val isMavenAccessible = System.getProperty("buildSrc.maven.accessible")?.toBoolean() ?: if (!mavenCentralTestUrl.isNullOrBlank()) {
```
##########
buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy:
##########
@@ -19,10 +19,51 @@
package org.apache.beam.gradle
import org.gradle.api.Project
+import java.net.HttpURLConnection
+import java.net.URL
Review Comment:

Add `java.net.URI` to the imports to support a more robust way of creating URLs, avoiding the deprecated `URL(String)` constructor.
```
import java.net.HttpURLConnection
import java.net.URL
import java.net.URI
```
##########
settings.gradle.kts:
##########
@@ -18,6 +18,41 @@
import com.gradle.enterprise.gradleplugin.internal.extension.BuildScanExtensionWithHiddenFeatures
pluginManagement {
+ val mavenCentralTestUrl = settings.providers.gradleProperty("mavenCentralTestUrl").orNull
+ val mavenCentralMirrorUrl = settings.providers.gradleProperty("mavenCentralMirrorUrl").orNull
+
+ val isMavenAccessible = if (!mavenCentralTestUrl.isNullOrBlank()) {
+ try {
+ val connection = java.net.URL(mavenCentralTestUrl).openConnection() as java.net.HttpURLConnection
Review Comment:

The `URL(String)` constructor is deprecated since Java 20. Use `java.net.URI(mavenCentralTestUrl).toURL()` instead.
```kotlin
val connection = java.net.URI(mavenCentralTestUrl).toURL().openConnection() as java.net.HttpURLConnection
```
##########
buildSrc/settings.gradle.kts:
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Properties
+
+pluginManagement {
+ val parentProperties = java.util.Properties().apply {
+ val file = file("../gradle.properties")
+ if (file.exists()) {
+ file.inputStream().use { load(it) }
+ }
+ }
+
+ val mavenCentralTestUrl = parentProperties.getProperty("mavenCentralTestUrl")
+ val mavenCentralMirrorUrl = parentProperties.getProperty("mavenCentralMirrorUrl")
+
+ val isMavenAccessible = if (!mavenCentralTestUrl.isNullOrBlank()) {
+ try {
+ val connection = java.net.URL(mavenCentralTestUrl).openConnection() as java.net.HttpURLConnection
Review Comment:

The `URL(String)` constructor is deprecated since Java 20. Use `java.net.URI(mavenCentralTestUrl).toURL()` instead.
```kotlin
val connection = java.net.URI(mavenCentralTestUrl).toURL().openConnection() as java.net.HttpURLConnection
```
##########
buildSrc/src/main/groovy/org/apache/beam/gradle/Repositories.groovy:
##########
@@ -19,10 +19,51 @@
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(Project project) {
+ if (isMavenAccessible != null) {
+ return isMavenAccessible
+ }
+ def testUrl = project.findProperty("mavenCentralTestUrl")
+ if (!testUrl) {
+ isMavenAccessible = true
+ return isMavenAccessible
+ }
+ try {
+ def url = new URL(testUrl)
Review Comment:

The `URL(String)` constructor is deprecated since Java 20. Use `new URI(testUrl).toURL()` instead.
```
def url = new URI(testUrl).toURL()
```
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fallback to Google Maven Mirror on Maven Central block/throttle [beam]
Posted by "shunping (via GitHub)" <gi...@apache.org>.
shunping commented on code in PR #38586:
URL: https://github.com/apache/beam/pull/38586#discussion_r3282615231
##########
buildSrc/settings.gradle.kts:
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Properties
+
+pluginManagement {
Review Comment:
Here we need to add another `settings.gradle.kts` under buildSrc.
The reason is three-folded:
- First, buildSrc compiles as an isolated, nested build before the main project's settings or code are processed. It does not inherit the parent project's repository definitions.
- Second, Transitive plugin dependencies (such as the Spotless formatting library dependencies) are resolved during a bootstrap phase before any code inside buildSrc/build.gradle.kts (including its repositories {} block) is compiled or evaluated.
- Third, By creating buildSrc/settings.gradle.kts, it allows us to define a pluginManagement.repositories block specifically prior to buildSrc’s bootstrap phase.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fallback to Google Maven Mirror on Maven Central block/throttle [beam]
Posted by "shunping (via GitHub)" <gi...@apache.org>.
shunping commented on PR #38586:
URL: https://github.com/apache/beam/pull/38586#issuecomment-4509503963
r: @Abacn
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fallback to Google Maven Mirror on Maven Central block/throttle [beam]
Posted by "shunping (via GitHub)" <gi...@apache.org>.
shunping commented on code in PR #38586:
URL: https://github.com/apache/beam/pull/38586#discussion_r3282279740
##########
settings.gradle.kts:
##########
@@ -18,6 +18,33 @@
import com.gradle.enterprise.gradleplugin.internal.extension.BuildScanExtensionWithHiddenFeatures
pluginManagement {
+ val isMavenAccessible = try {
+ 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
+ connection.requestMethod = "GET"
+ connection.setRequestProperty("User-Agent", "Gradle")
+ connection.connectTimeout = 2000
+ connection.readTimeout = 2000
+ connection.useCaches = false
+ connection.responseCode == 200
+ } catch (e: Exception) {
+ false
+ }
+ val mavenCentralMirrorUrl = "https://maven-central.storage-download.googleapis.com/maven2/"
+
+ if (isMavenAccessible) {
+ logger.lifecycle("Maven Central is accessible. Using default repositories for settings plugins.")
+ } else {
+ logger.lifecycle("Maven Central is not accessible. Falling back to Google Maven Mirror for settings plugins.")
+ }
+
+ repositories {
+ if (isMavenAccessible) {
+ gradlePluginPortal()
+ } else {
+ maven { url = uri(mavenCentralMirrorUrl) }
+ gradlePluginPortal()
+ }
Review Comment:
Done.
##########
buildSrc/build.gradle.kts:
##########
@@ -25,7 +52,12 @@ plugins {
// Define the set of repositories required to fetch and enable plugins.
repositories {
- maven { url = uri("https://plugins.gradle.org/m2/") }
+ if (isMavenAccessible) {
+ maven { url = uri("https://plugins.gradle.org/m2/") }
+ } else {
+ maven { url = uri(mavenCentralMirrorUrl) }
+ maven { url = uri("https://plugins.gradle.org/m2/") }
+ }
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org