{"record":{"id":"c66a62c030833acd","repo":"elastic/elasticsearch","slug":"buildresources-can-t-be-configured-after-the-task","errorCode":null,"errorMessage":"buildResources can't be configured after the task ran. Make sure task is not used after configuration time","messagePattern":"buildResources can't be configured after the task ran\\. Make sure task is not used after configuration time","errorType":"validation","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ExportElasticsearchBuildResourcesTask.java","lineNumber":89,"sourceCode":"    }\n\n    public void setOutputDir(File outputDir) {\n        this.outputDir.set(outputDir);\n    }\n\n    /**\n     * Copy a resource to the output directory, keeping the original filename.\n     */\n    public void copy(String resource) {\n        copy(resource, resource);\n    }\n\n    /**\n     * Copy a resource to the output directory with a different filename.\n     */\n    public void copy(String resource, String destName) {\n        if (getState().getExecuted() || getState().getExecuting()) {\n            throw new GradleException(\n                \"buildResources can't be configured after the task ran. \" + \"Make sure task is not used after configuration time\"\n            );\n        }\n        resources.put(resource, destName);\n    }\n\n    @TaskAction\n    public void doExport() {\n        if (resources.isEmpty()) {\n            setDidWork(false);\n            throw new StopExecutionException();\n        }\n        resources.entrySet().stream().parallel().forEach(entry -> {\n            String resourcePath = entry.getKey();\n            String destName = entry.getValue();\n            Path destination = outputDir.get().file(destName).getAsFile().toPath();\n            try (InputStream is = getClass().getClassLoader().getResourceAsStream(resourcePath)) {\n                Files.createDirectories(destination.getParent());","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ExportElasticsearchBuildResourcesTask.java#L71-L107","documentation":"Thrown by ExportElasticsearchBuildResourcesTask.copy when the task has already executed or is currently executing (getState().getExecuted() || getState().getExecuting()). Resource registration must happen during Gradle's configuration phase; calling copy(...) after the task graph ran is a configuration-vs-execution misuse.","triggerScenarios":"Invoking task.copy(resource) from an afterEvaluate, doFirst, doLast, or another task's action that runs after this task has executed.","commonSituations":"Wiring resource export inside an action closure rather than at configuration time; reusing a task instance across builds in the same daemon.","solutions":["Register all resources during the configuration phase, directly in the build script or plugin apply, not in a doFirst/doLast.","Avoid holding task references and mutating them after the task graph executes.","If late binding is needed, use a Provider/Property so configuration is lazy."],"exampleFix":"// before\nmyExportTask.doFirst { t -> t.copy('extra.txt') }\n// after\nmyExportTask.copy('extra.txt')  // at configuration time","handlingStrategy":"validation","validationCode":"if (getState().getExecuted() || getState().getExecuting()) {\n    throw new GradleException(\"buildResources can't be configured after the task ran.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Register all resources during the configuration phase only.","Never call task mutation methods from doFirst/doLast/afterEvaluate that run post-execution.","Use lazy Providers/Properties if late-bound inputs are required."],"tags":["gradle","task-lifecycle","configuration-time","build-tools"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}