gradle/gradle · error · ServiceLookupException
Can not inject RepositoryResourceAccessor since repository h
Error message
Can not inject RepositoryResourceAccessor since repository has no URL.
What it means
Component metadata rules declared on a repository get services injected through a tiny service registry: ObjectFactory always, plus RepositoryResourceAccessor only when the repository has a URL (something to access). If a rule requests RepositoryResourceAccessor on a URL-less repository, the lookup throws ServiceLookupException 'Can not inject RepositoryResourceAccessor since repository has no URL.'
Source
Thrown at platforms/software/dependency-management/src/main/java/org/gradle/api/internal/artifacts/repositories/AbstractArtifactRepository.java:217
private static class RepositoryRuleServiceLookup implements ServiceLookup {
private final ObjectFactory objectFactory;
private final @Nullable RepositoryResourceAccessor repositoryResourceAccessor;
public RepositoryRuleServiceLookup(
ObjectFactory objectFactory,
@Nullable RepositoryResourceAccessor repositoryResourceAccessor
) {
this.objectFactory = objectFactory;
this.repositoryResourceAccessor = repositoryResourceAccessor;
}
@Override
public @Nullable Object find(Type serviceType) throws ServiceLookupException {
if (serviceType == RepositoryResourceAccessor.class) {
if (repositoryResourceAccessor == null) {
throw new ServiceLookupException("Can not inject RepositoryResourceAccessor since repository has no URL.");
} else {
return repositoryResourceAccessor;
}
} else if (serviceType == ObjectFactory.class) {
return objectFactory;
}
return null;
}
@Override
public Object get(Type serviceType) throws UnknownServiceException, ServiceLookupException {
Object service = find(serviceType);
if (service != null) {
return service;
}
throw new UnknownServiceException(serviceType, "Service of type " + serviceType + " is not available for repository metadata rules. Available services: " + availableServicesDescription() + ".");
}View on GitHub (pinned to 534f27719b)
Solutions
- Set the repository URL before resolution: repo.setUrl(uri('https://repo.example.com/maven')).
- Register accessor-dependent rules only on repositories where url != null (guard in plugin or build logic).
- Split rules: those needing remote fetch go on URL-backed repositories only; pure metadata rules drop the accessor injection.
Example fix
// before
repositories.maven {
name = 'custom'
// no URL configured
componentMetadata { module('com.example:*') { all(MyRemoteFetchingRule) } } // rule injects RepositoryResourceAccessor
}
// after
repositories.maven {
name = 'custom'
setUrl('https://repo.example.com/maven')
componentMetadata { module('com.example:*') { all(MyRemoteFetchingRule) } }
} Defensive patterns
Strategy: validation
Validate before calling
if (repo instanceof MavenArtifactRepository && repo.url != null) {
repo.componentMetadata {
// rules that inject RepositoryResourceAccessor
}
} else {
logger.warn('Skipping remote-fetch metadata rule on repository without URL: ' + repo.name)
} Prevention
- Set repository URLs before registering metadata rules
- In plugins, attach accessor-dependent rules only when url != null
- Keep remote-fetching rules and pure metadata rules separate
When it happens
Trigger: Declaring a repository componentMetadata / metadataSupplier rule whose action class has a RepositoryResourceAccessor parameter while the repository's URL was never set (or is set only later, after the rule is registered), then triggering resolution so the rule is instantiated.
Common situations: Plugins attaching metadata rules to every repository indiscriminately, including not-yet-configured ones; repositories whose URL is supplied later by environment-specific logic; local-only repositories with no remote to fetch from.
Related errors
- Service of type {} is not available for repository metadata
- Service of type {} annotated with @{} is not available for r
- Could not add URLs %s to class path for ClassLoader %s
- Cannot determine classpath for resource '%s' from location '
- Cannot parse file URL {location}
AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22).
Data as JSON: /api/errors/49ccb9dc84927150.
Report an issue: GitHub.