{"record":{"id":"53a2c52d3f035165","repo":"elastic/elasticsearch","slug":"unable-to-find-build-service-with-name","errorCode":null,"errorMessage":"Unable to find build service with name '{}'.","messagePattern":"Unable to find build service with name '(.+?)'\\.","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"build-tools/src/main/java/org/elasticsearch/gradle/util/GradleUtils.java","lineNumber":75,"sourceCode":"        tasks.withType(type).matching((Spec<T>) t -> t.getName().equals(name)).configureEach(config);\n    }\n\n    public static TaskProvider<?> findByName(TaskContainer tasks, String name) {\n        TaskProvider<?> task;\n        try {\n            task = tasks.named(name);\n        } catch (UnknownTaskException e) {\n            return null;\n        }\n\n        return task;\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public static <T extends BuildService<?>> Provider<T> getBuildService(BuildServiceRegistry registry, String name) {\n        BuildServiceRegistration<?, ?> registration = registry.getRegistrations().findByName(name);\n        if (registration == null) {\n            throw new GradleException(\"Unable to find build service with name '\" + name + \"'.\");\n        }\n\n        return (Provider<T>) registration.getService();\n    }\n\n    /**\n     * Add a source set and task of the same name that runs tests.\n     * <p>\n     * IDEs are also configured if setup, and the test task is added to check. The new test source\n     * set extends from the normal test source set to allow sharing of utilities.\n     *\n     * @return A task provider for the newly created test task\n     */\n    public static TaskProvider<Test> addTestSourceSet(Project project, String sourceSetName) {\n        project.getPluginManager().apply(JavaPlugin.class);\n\n        // create our test source set and task\n        SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools/src/main/java/org/elasticsearch/gradle/util/GradleUtils.java#L57-L93","documentation":"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.","triggerScenarios":"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()).","commonSituations":"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.","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."],"exampleFix":"// before\nProvider<MyService> svc = GradleUtils.getBuildService(project.getGradle().getSharedServices(), \"myService\");\n// after\n// ensure registration exists first (e.g. in an applied plugin)\nproject.getGradle().getSharedServices().registerIfAbsent(\"myService\", MyService.class, spec -> {});\nProvider<MyService> svc = GradleUtils.getBuildService(project.getGradle().getSharedServices(), \"myService\");","handlingStrategy":"validation","validationCode":"BuildServiceRegistration<?, ?> reg = project.getGradle().getSharedServices().getRegistrations().findByName(name);\nif (reg == null) {\n    throw new IllegalStateException(\"Build service '\" + name + \"' is not registered. Apply the owning plugin first.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Provider<T> svc = GradleUtils.getBuildService(registry, name);\n} catch (GradleException e) {\n    // service missing — register it or rethrow with the owning-plugin hint\n    throw new GradleException(\"Missing build service '\" + name + \"'; apply the registering plugin first\", e);\n}","preventionTips":["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())."],"tags":["gradle","build-service","configuration-time","build-tools"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}