{"record":{"id":"c6d6d247fb4eb22c","repo":"elastic/elasticsearch","slug":"task-is-not-configured-to-use-any-clusters-be","errorCode":null,"errorMessage":"Task {} is not configured to use any clusters. Be sure to call useCluster().","messagePattern":"Task (.+?) is not configured to use any clusters\\. Be sure to call useCluster\\(\\)\\.","errorType":"validation","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"build-tools/src/main/java/org/elasticsearch/gradle/testclusters/RunTask.java","lineNumber":360,"sourceCode":"                }\n\n            }\n        }\n        if (debug) {\n            enableDebug();\n        }\n        if (cliDebug) {\n            enableCliDebug();\n        }\n    }\n\n    @TaskAction\n    public void runAndWait() throws IOException {\n        List<BufferedReader> toRead = new ArrayList<>();\n        List<BooleanSupplier> aliveChecks = new ArrayList<>();\n\n        if (getClusters().isEmpty()) {\n            throw new GradleException(\"Task \" + getPath() + \" is not configured to use any clusters. Be sure to call useCluster().\");\n        }\n\n        try {\n            for (ElasticsearchCluster cluster : getClusters()) {\n                cluster.writeUnicastHostsFiles();\n                for (ElasticsearchNode node : cluster.getNodes()) {\n                    BufferedReader reader = Files.newBufferedReader(node.getEsOutputFile());\n                    toRead.add(reader);\n                    aliveChecks.add(node::isProcessAlive);\n                }\n            }\n\n            while (Thread.currentThread().isInterrupted() == false) {\n                boolean readData = false;\n                for (BufferedReader bufferedReader : toRead) {\n                    if (bufferedReader.ready()) {\n                        readData = true;\n                        logger.lifecycle(bufferedReader.readLine());","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/RunTask.java#L342-L378","documentation":"Thrown by RunTask.runAndWait() at task-execution time when the `useCluster(...)` method was never called on the task, so `getClusters()` is empty. RunTask is a `@TaskAction` that must stream logs from at least one ElasticsearchCluster node; with no clusters registered there is nothing to run and the build aborts. This is a configuration-time defect surfaced at execution time, not an environment failure.","triggerScenarios":"Invoking a `RunTask` (e.g. a task of type `elasticsearch.testclusters.run` / a custom `run` task) whose build script never called `task.useCluster(cluster)`. Also happens when the cluster property is wired via a Provider that resolved to empty, or when a subclass overrode configuration hooks and skipped the registration.","commonSituations":"A developer copies a `run { ... }` block from another project but forgets the `useCluster(...)` line; refactoring a test that used `ESIntegTestCase` into a standalone run task; renaming a cluster property so `useCluster(oldName)` silently no-ops because the reference was never reified.","solutions":["In the task configuration block, call `useCluster(testClusters.<name>)` so the task is bound to a declared `ElasticsearchCluster`.","Verify the cluster is declared in the same project (cross-project use throws a different error, #110) and that its name matches the task or is referenced explicitly.","If subclassing RunTask, ensure super-configuration or an explicit `useCluster` call runs; do not rely on lazy providers that may never resolve before execution.","Run `./gradlew <task> --info` and confirm `getClusters()` is populated before the `@TaskAction` fires."],"exampleFix":"// before\nrun {\n  // cluster declared but never wired\n}\n// after\nrun {\n  useCluster(testClusters.myCluster)\n}","handlingStrategy":"validation","validationCode":"// Before depending on this task, assert a cluster is wired\nif (task.getClusters().isEmpty()) {\n  throw new GradleException(\"Configure useCluster(...) on \" + task.getPath());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat `useCluster(...)` as a mandatory call in any RunTask configuration block; add a lint check in a convention plugin.","When refactoring cluster declarations, grep for `useCluster(` references that point at the old name and update them.","Add a `doFirst { assert !getClusters().isEmpty() }` guard to fail with a clearer message before the @TaskAction."],"tags":["gradle","testclusters","configuration","build-tools"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}