{"record":{"id":"ebe974fe89f7ef93","repo":"quarkusio/quarkus","slug":"failed-to-initialize-file-output-writer-ebe974","errorCode":null,"errorMessage":"Failed to initialize file output writer","messagePattern":"Failed to initialize file output writer","errorType":"exception","errorClass":"MojoExecutionException","httpStatus":null,"severity":"error","filePath":"devtools/maven/src/main/java/io/quarkus/maven/DependencyTreeMojo.java","lineNumber":111,"sourceCode":"    protected MavenArtifactResolver resolver;\n\n    @Override\n    public void execute() throws MojoExecutionException, MojoFailureException {\n\n        BufferedWriter writer = null;\n        final Consumer<String> log;\n        if (outputFile == null) {\n            log = s -> getLog().info(s);\n        } else {\n            final BufferedWriter bw;\n            try {\n                Files.createDirectories(outputFile.toPath().getParent());\n                final OpenOption[] openOptions = appendOutput && outputFile.exists()\n                        ? new OpenOption[] { StandardOpenOption.APPEND }\n                        : new OpenOption[0];\n                bw = writer = Files.newBufferedWriter(outputFile.toPath(), openOptions);\n            } catch (IOException e) {\n                throw new MojoExecutionException(\"Failed to initialize file output writer\", e);\n            }\n            log = s -> {\n                try {\n                    bw.write(s);\n                    bw.newLine();\n                } catch (IOException e) {\n                    throw new RuntimeException(\"Failed to log the dependency tree to a file\", e);\n                }\n            };\n        }\n        try {\n            logTree(log);\n        } finally {\n            if (writer != null) {\n                try {\n                    writer.close();\n                } catch (IOException e) {\n                    getLog().debug(\"Failed to close the output file\", e);","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/devtools/maven/src/main/java/io/quarkus/maven/DependencyTreeMojo.java#L93-L129","documentation":"DependencyTreeMojo writes the dependency tree to outputFile when configured. It creates parent directories and opens a BufferedWriter (with APPEND if appendOutput and the file exists); any IOException is wrapped in a MojoExecutionException 'Failed to initialize file output writer', aborting before the tree is rendered.","triggerScenarios":"Running quarkus:dependency-tree with an output file target that cannot be opened — permission denied, parent path is a file, invalid path, or underlying filesystem I/O error.","commonSituations":"Read-only CI workspaces; outputFile inside a non-existent non-creatable location; parent directory existing as a file; volume mount permission issues in containers; disk full.","solutions":["Fix permissions on the target directory or choose a writable outputFile path","Ensure the parent path is a directory (or removable so it can be created)","Check disk space","Default to console output (omit outputFile) if file output is not essential"],"exampleFix":"// before\nmvn quarkus:dependency-tree -DoutputFile=/etc/deptree.txt\n// after\nmvn quarkus:dependency-tree -DoutputFile=${project.build.directory}/deptree.txt","handlingStrategy":"validation","validationCode":"// Pre-check output file writability before running the goal\njava.nio.file.Path out = java.nio.file.Path.of(outputFile);\njava.nio.file.Path parent = out.toAbsolutePath().getParent();\nif (parent == null || !java.nio.file.Files.isDirectory(parent) && !parent.toFile().mkdirs()) {\n    throw new IllegalStateException(\"Cannot create directory: \" + parent);\n}\nif (!java.nio.file.Files.isWritable(parent)) {\n    throw new IllegalStateException(\"Directory not writable: \" + parent);\n}","typeGuard":null,"tryCatchPattern":"try {\n    mvn quarkus:dependency-tree -DoutputFile=target/tree.txt;\n} catch (MojoExecutionException e) {\n    if (\"Failed to initialize file output writer\".equals(e.getMessage())) {\n        // check e.getCause() (IOException): permissions/path/disk, fix and retry\n    }\n}","preventionTips":["Write tree output under ${project.build.directory}, never system paths","Ensure parent directories exist and are writable before CI runs","Avoid system/read-only locations when running in containers","Keep adequate free disk space on build agents"],"tags":["maven","io","file-write","build"],"backgroundTag":"file-write-permission-denied","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}