From 734a0e8339608b49c8a0bff85e7ac302bbb0f1f2 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Tue, 3 Feb 2026 13:35:29 +0200 Subject: [PATCH] Add support for custom Maven repository URLs --- src/mx/_impl/mx.py | 5 +---- src/mx/_impl/mx_maven.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/mx/_impl/mx.py b/src/mx/_impl/mx.py index 8772f2793..815c591cb 100755 --- a/src/mx/_impl/mx.py +++ b/src/mx/_impl/mx.py @@ -828,6 +828,7 @@ def format_help(self): MX_CACHE_DIR Override the default location of the mx download cache. Defaults to `~/.mx/cache`. MX_GLOBAL_ENV Override the default location of the global env file that is always loaded at startup. Defaults to `~/.mx/env`. Can be disabled by setting it to an empty string. + MX_MAVEN_REPO_URLS Comma-separated list of Maven repository base URLs. Defaults to Maven Central repositories. MX_GIT_CACHE Use a cache for git objects during clones. * Setting it to `reference` will clone repositories using the cache and let them reference the cache (if the cache gets deleted these repositories will be @@ -4566,10 +4567,6 @@ def _zipfile_exit(self, t, value, traceback): _distTemplates = {} _licenses = {} _repositories = {} -_mavenRepoBaseURLs = [ - "https://repo1.maven.org/maven2/", - "https://search.maven.org/remotecontent?filepath=" -] """ Map of the environment variables loaded by parsing the suites. diff --git a/src/mx/_impl/mx_maven.py b/src/mx/_impl/mx_maven.py index a3e96bda7..39c07490c 100644 --- a/src/mx/_impl/mx_maven.py +++ b/src/mx/_impl/mx_maven.py @@ -283,10 +283,29 @@ def resolveLicenses(self): return _maven_local_repository +_resolved_maven_repo_base_urls = False +def _get_maven_repo_base_urls(): + """ + Gets the Maven repository base URLs from the MX_MAVEN_REPO_URLS environment variable. + If not set, returns the default Maven Central repositories. + The environment variable should contain a comma-separated list of URLs. + """ + default_urls = [ + "https://repo1.maven.org/maven2/", + "https://search.maven.org/remotecontent?filepath=" + ] + global _resolved_maven_repo_base_urls + if _resolved_maven_repo_base_urls is False: + urls = mx.get_env('MX_MAVEN_REPO_URLS') + if urls: + _resolved_maven_repo_base_urls = urls.split(',') + else: + _resolved_maven_repo_base_urls = default_urls + return _resolved_maven_repo_base_urls def maven_download_urls(groupId, artifactId, version, classifier=None, baseURL=None): if baseURL is None: - baseURLs = mx._mavenRepoBaseURLs + baseURLs = _get_maven_repo_base_urls() else: baseURLs = [baseURL] classifier = f'-{classifier}' if classifier else ''