Allow configuring a Maven Central mirror via system property#6712
Allow configuring a Maven Central mirror via system property#6712yzfeng2020 wants to merge 1 commit intoline:mainfrom
Conversation
Add support for a `mavenCentralMirror` system property that allows users behind corporate proxies or firewalls to redirect all Maven Central traffic through a mirror repository. Users can configure this in `~/.gradle/gradle.properties`: systemProp.mavenCentralMirror=https://your-mirror.example.com When unset, behavior is identical to today (uses mavenCentral()). Co-authored-by: Isaac
60952ae to
3ec6509
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6712 +/- ##
============================================
- Coverage 74.46% 73.99% -0.47%
- Complexity 22234 24121 +1887
============================================
Files 1963 2176 +213
Lines 82437 90501 +8064
Branches 10764 11859 +1095
============================================
+ Hits 61385 66970 +5585
- Misses 15918 17915 +1997
- Partials 5134 5616 +482 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughGradle build configuration files are updated to conditionally resolve Maven artifacts from a custom mirror URL via the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
jrhee17
left a comment
There was a problem hiding this comment.
Overall looks good, left some questions
| } else { | ||
| mavenCentral() | ||
| } | ||
| gradlePluginPortal() |
There was a problem hiding this comment.
Question) Just to be sure, the target is only mavenCentral and not other repositories - is my understanding correct?
| buildscript { | ||
| repositories { | ||
| mavenCentral() | ||
| def mavenCentralMirror = System.getProperty('mavenCentralMirror') |
There was a problem hiding this comment.
Note: This is unfortunate, we should move on to using conventions plugins instead so that we don't have to redeclare this for every buildscript closure
| // ~/.gradle/gradle.properties to redirect all Maven Central requests to a mirror. | ||
| pluginManagement { | ||
| repositories { | ||
| def mavenCentralMirror = System.getProperty('mavenCentralMirror') |
There was a problem hiding this comment.
Question) Is it possible to use gradle properties (providers.gradleProperty or project.findProperty) instead of system properties? (in case we want finer control over overwriting per project, etc. in the future)
|
Would we follow the style used for OSS Sonatype URL? Lines 17 to 18 in 339b5dd |
Motivation
Due to recent supply chain security concerns, many organizations block direct access to Maven Central and route artifact downloads through an internal mirror or proxy for auditing and control.
Armeria's build currently hardcodes
mavenCentral()andgradlePluginPortal()across multiple Gradle scripts, includingbuildscript {}blocks inapply from:scripts that cannot be overridden via Gradle init scripts. This makes it impossible to build Armeria in restricted network environments without modifying project files directly.Modifications
mavenCentralMirrorJava system property recognized by all repository declarations.mavenCentral()(and supplements it where appropriate).pluginManagementblock tosettings.gradleto cover settings-level plugin resolution.Usage
Add to
~/.gradle/gradle.properties:systemProp.mavenCentralMirror=https://your-mirror.example.comOr pass via the CLI:
Why
System.getProperty()instead of Gradle project properties?buildscript {}blocks inapply from:scripts use separateScriptHandlerobjects that cannot access project-level extensions or properties.System.getProperty()is the only mechanism available in all evaluation contexts:settings.gradle,buildSrc, and applied scripts'buildscript {}blocks.Result
mavenCentralMirroris set: all Maven Central traffic is routed through the specified mirror.mavenCentralMirroris not set: no behavior change.