elastic/elasticsearch · error · GradleException
Unable to find build service with name '{}'.
Error message
Unable to find build service with name '{}'. What it means
Thrown by GradleUtils.getBuildService at build-configuration time when no BuildServiceRegistration with the requested name exists in the Gradle BuildServiceRegistry. The helper looks up the registration via registry.getRegistrations().findByName(name); a null result means the shared build service was never registered. It almost always signals a plugin-ordering, naming, or registry-scope problem.
Source
Thrown at build-tools/src/main/java/org/elasticsearch/gradle/util/GradleUtils.java:75
tasks.withType(type).matching((Spec<T>) t -> t.getName().equals(name)).configureEach(config);
}
public static TaskProvider<?> findByName(TaskContainer tasks, String name) {
TaskProvider<?> task;
try {
task = tasks.named(name);
} catch (UnknownTaskException e) {
return null;
}
return task;
}
@SuppressWarnings("unchecked")
public static <T extends BuildService<?>> Provider<T> getBuildService(BuildServiceRegistry registry, String name) {
BuildServiceRegistration<?, ?> registration = registry.getRegistrations().findByName(name);
if (registration == null) {
throw new GradleException("Unable to find build service with name '" + name + "'.");
}
return (Provider<T>) registration.getService();
}
/**
* Add a source set and task of the same name that runs tests.
* <p>
* IDEs are also configured if setup, and the test task is added to check. The new test source
* set extends from the normal test source set to allow sharing of utilities.
*
* @return A task provider for the newly created test task
*/
public static TaskProvider<Test> addTestSourceSet(Project project, String sourceSetName) {
project.getPluginManager().apply(JavaPlugin.class);
// create our test source set and task
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);View on GitHub (pinned to db6a809a66)
Solutions
- Register the build service with registerIfAbsent on the same registry instance before calling getBuildService.
- Verify the service name string matches the registration name exactly (case-sensitive, no trailing whitespace).
- Apply the owning plugin in the root project's plugin block so registration precedes all consumers.
- If writing a custom plugin, register lazily in a Plugin<Project>.apply rather than eagerly at evaluation.
Example fix
// before
Provider<MyService> svc = GradleUtils.getBuildService(project.getGradle().getSharedServices(), "myService");
// after
// ensure registration exists first (e.g. in an applied plugin)
project.getGradle().getSharedServices().registerIfAbsent("myService", MyService.class, spec -> {});
Provider<MyService> svc = GradleUtils.getBuildService(project.getGradle().getSharedServices(), "myService"); Defensive patterns
Strategy: validation
Validate before calling
BuildServiceRegistration<?, ?> reg = project.getGradle().getSharedServices().getRegistrations().findByName(name);
if (reg == null) {
throw new IllegalStateException("Build service '" + name + "' is not registered. Apply the owning plugin first.");
} Try / catch
try {
Provider<T> svc = GradleUtils.getBuildService(registry, name);
} catch (GradleException e) {
// service missing — register it or rethrow with the owning-plugin hint
throw new GradleException("Missing build service '" + name + "'; apply the registering plugin first", e);
} Prevention
- Register shared build services in a root-project convention plugin applied before any consumer.
- Centralize service-name strings in constants to avoid typos.
- Always look up via the same registry instance used for registration (gradle.getSharedServices()).
When it happens
Trigger: Calling GradleUtils.getBuildService(project.getGradle().getSharedServices(), "someName") where no plugin has called registerIfAbsent("someName", ...) on the same registry, or where registration happened on a different Gradle instance (e.g. a per-project gradle vs the root gradle.getSharedServices()).
Common situations: The plugin that owns the service was not applied before the consumer; the service name string is misspelled or has wrong case; registration is scoped to a subproject's buildscript while the lookup runs against the root Gradle shared services.
Related errors
- elasticsearch.standalone-test, elasticsearch.standalone-rest
- buildResources can't be configured after the task ran. Make
- platform cannot be set on elasticsearch distribution [${name
- bundledJdk cannot be set on elasticsearch distribution [${na
- ${className} does not support remove()
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/53a2c52d3f035165.
Report an issue: GitHub.