@@ -18,7 +18,13 @@ import { getMavenConfig } from '../config'
1818import { extractArtifact , getPomCacheStats , normalizeScmUrl } from './extract'
1919import { isMavenFetchError , resolveVersionsList } from './metadata'
2020import { isPrerelease , parseRepoUrl } from './normalize'
21- import { resolveRegistryBaseUrl , resolveRegistryPageUrl } from './registry'
21+ import {
22+ MAVEN_CENTRAL_BASE_URL ,
23+ isAlternativeRegistry ,
24+ resolveRegistryBaseUrl ,
25+ resolveRegistryPageUrl ,
26+ resolveRegistryPageUrlFromBase ,
27+ } from './registry'
2228
2329const log = getServiceChildLogger ( 'maven' )
2430
@@ -115,10 +121,25 @@ async function processCriticalPackage(qx: QueryExecutor, pkg: PackageRow, forceF
115121 return { status : 'skipped' }
116122 }
117123
118- const baseUrl = resolveRegistryBaseUrl ( groupId )
124+ let baseUrl = resolveRegistryBaseUrl ( groupId )
119125
120126 // Phase 1: lightweight metadata fetch to get the current upstream version.
121- const metadata = await resolveVersionsList ( groupId , artifactId , baseUrl )
127+ let metadata = await resolveVersionsList ( groupId , artifactId , baseUrl )
128+
129+ // If the primary (non-Central) registry returned NOT_FOUND, try Maven Central as a
130+ // fallback. This handles artifacts that share a namespace with non-Central packages but
131+ // are themselves published on Central — e.g. com.google.firebase:firebase-admin is the
132+ // server-side Java SDK on Central, while most com.google.firebase artifacts are Android
133+ // SDKs on Google Maven.
134+ if ( isMavenFetchError ( metadata ) && metadata . kind === 'NOT_FOUND' && isAlternativeRegistry ( groupId ) ) {
135+ const centralUrl = process . env . MAVEN_FETCHER_BASE_URL ?? MAVEN_CENTRAL_BASE_URL
136+ const centralMetadata = await resolveVersionsList ( groupId , artifactId , centralUrl )
137+ if ( ! isMavenFetchError ( centralMetadata ) ) {
138+ log . info ( { groupId, artifactId } , 'Not found in primary registry — resolved via Maven Central fallback' )
139+ baseUrl = centralUrl
140+ metadata = centralMetadata
141+ }
142+ }
122143
123144 if ( isMavenFetchError ( metadata ) ) {
124145 if ( metadata . kind === 'NOT_FOUND' ) {
@@ -129,7 +150,7 @@ async function processCriticalPackage(qx: QueryExecutor, pkg: PackageRow, forceF
129150 name : artifactId ,
130151 description : null ,
131152 homepage : null ,
132- registryUrl : resolveRegistryPageUrl ( groupId , artifactId ) ,
153+ registryUrl : resolveRegistryPageUrlFromBase ( groupId , artifactId , baseUrl ) ,
133154 declaredRepositoryUrl : null ,
134155 repositoryUrl : null ,
135156 licenses : null ,
@@ -164,7 +185,7 @@ async function processCriticalPackage(qx: QueryExecutor, pkg: PackageRow, forceF
164185 name : artifactId ,
165186 description : null ,
166187 homepage : null ,
167- registryUrl : resolveRegistryPageUrl ( groupId , artifactId ) ,
188+ registryUrl : resolveRegistryPageUrlFromBase ( groupId , artifactId , baseUrl ) ,
168189 declaredRepositoryUrl : null ,
169190 repositoryUrl : null ,
170191 licenses : null ,
@@ -201,7 +222,7 @@ async function processCriticalPackage(qx: QueryExecutor, pkg: PackageRow, forceF
201222 name : artifactId ,
202223 description : null ,
203224 homepage : null ,
204- registryUrl : resolveRegistryPageUrl ( groupId , artifactId ) ,
225+ registryUrl : resolveRegistryPageUrlFromBase ( groupId , artifactId , baseUrl ) ,
205226 declaredRepositoryUrl : null ,
206227 repositoryUrl : null ,
207228 licenses : null ,
@@ -227,7 +248,7 @@ async function processCriticalPackage(qx: QueryExecutor, pkg: PackageRow, forceF
227248 name : artifactId ,
228249 description : result . description ,
229250 homepage : result . homepageUrl ,
230- registryUrl : resolveRegistryPageUrl ( groupId , artifactId ) ,
251+ registryUrl : resolveRegistryPageUrlFromBase ( groupId , artifactId , baseUrl ) ,
231252 declaredRepositoryUrl : result . scmUrl ,
232253 repositoryUrl,
233254 licenses : result . licenses . length > 0 ? result . licenses : null ,
0 commit comments