baomidou/mybatis-plus · error · IOException
Unable to create directory {}
Error message
Unable to create directory {} What it means
FileUtils.forceMkdir throws IOException when File.mkdirs() returns false AND a re-check confirms the directory still does not exist. This means the OS refused creation: a parent is not writable, a path component is a file, permissions are missing, or (rarely) a race deleted it between the two checks.
Source
Thrown at mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/util/FileUtils.java:56
*/
public static void forceMkdir(final File directory) throws IOException {
if (directory.exists()) {
if (!directory.isDirectory()) {
final String message =
"File "
+ directory
+ " exists and is "
+ "not a directory. Unable to create directory.";
throw new IOException(message);
}
} else {
if (!directory.mkdirs()) {
// Double-check that some other thread or process hasn't made
// the directory in the background
if (!directory.isDirectory()) {
final String message =
"Unable to create directory " + directory;
throw new IOException(message);
}
}
}
}
/**
* Makes any necessary but nonexistent parent directories for a given File. If the parent directory cannot be
* created then an IOException is thrown.
*
* @param file file with parent to create, must not be {@code null}
* @throws NullPointerException if the file is {@code null}
* @throws IOException if the parent directory cannot be created
* @since 2.5
*/
public static void forceMkdirParent(final File file) throws IOException {
final File parent = file.getParentFile();
if (parent == null) {
return;View on GitHub (pinned to bf67d90747)
Solutions
- Manually run `mkdir -p <path from message>` to get the real OS error (permission denied vs file exists).
- Choose an outputDir under a location you own (project target/, build dir) or grant write permission to the user running the generator.
- If a path component is a file, remove/rename it (see sibling error 67).
Example fix
# before (read-only path)
globalConfig.setOutputDir("/opt/app/src-gen");
# after
globalConfig.setOutputDir(System.getProperty("user.dir") + "/build/src-gen"); Defensive patterns
Strategy: validation
Validate before calling
File dir = new File(outputDir).getAbsoluteFile();
if (!dir.exists() && !dir.mkdirs()) {
throw new IllegalStateException("no write permission for outputDir: " + dir
+ " (writable=" + dir.getParentFile().canWrite() + ")");
} Try / catch
try {
generator.generate();
} catch (RuntimeException e) {
if (e.getCause() instanceof IOException io && io.getMessage().startsWith("Unable to create directory")) {
log.error("fix permissions on output dir; message names the path");
}
} Prevention
- Generate into project-local build directories, not system paths like /opt or /.
- In Docker/CI, mount a writable volume for the output dir.
- Verify the process user's write permission on every path component (mkdir -p dry run) in setup scripts.
When it happens
Trigger: Generating into a read-only or permission-restricted outputDir (e.g. '/' or '/opt/app' as non-root), a path where some intermediate component exists as a file, or sandboxed CI containers with a read-only filesystem layer.
Common situations: Running the generator in Docker/CI where the working dir is read-only; outputDir configured from a property that resolves to a path the current user cannot create; NFS mount with root_squash denying mkdir.
Related errors
- File {} exists and is not a directory. Unable to create dire
- An exception occurred in the output file:
- Illegal directory {}
- %s 的名称转换结果为空,请检查是否配置问题
- `include` and `exclude` configurations are mutually exclusiv
AI-assisted analysis of baomidou/mybatis-plus@bf67d90747 (2026-08-14).
Data as JSON: /api/errors/9fba4260975990e2.
Report an issue: GitHub.