OpenAPITools/openapi-generator · error · RuntimeException
Failed to create the folder " + parent.getAbsolutePath() + "
Error message
Failed to create the folder " + parent.getAbsolutePath() + " to store the checksum of the input spec.
What it means
After generation succeeds, CodeGenMojo stores a SHA-256 checksum of the input spec for incremental builds; this RuntimeException (not MojoExecutionException) means File.mkdirs() returned false while creating the parent directory of that checksum file (typically under output/src/main/java/... or the configured output plus .openapi-generator). mkdirs returns false both when creation fails (permissions, read-only mount) and when the path exists as a file or another thread created it concurrently — the code does not distinguish, and the raw RuntimeException then surfaces as 'unexpected error in Open-API generation'.
Source
Thrown at modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java:1130
+ langCliOption.getOptionHelp().replaceAll("\n", "\n\t "));
System.out.println();
}
return;
}
adjustAdditionalProperties(config);
GlobalSettings.log();
new DefaultGenerator(dryRun).opts(input).generate();
if (buildContext != null) {
buildContext.refresh(new File(getCompileSourceRoot()));
}
// Store a checksum of the input spec
File storedInputSpecHashFile = getHashFile(inputSpecFile);
if (storedInputSpecHashFile.getParent() != null && !new File(storedInputSpecHashFile.getParent()).exists()) {
File parent = new File(storedInputSpecHashFile.getParent());
if (!parent.mkdirs()) {
throw new RuntimeException("Failed to create the folder " + parent.getAbsolutePath() +
" to store the checksum of the input spec.");
}
}
Files.asCharSink(storedInputSpecHashFile, StandardCharsets.UTF_8).write(calculateInputSpecHash(inputSpec));
} catch (Exception e) {
// Maven logs exceptions thrown by plugins only if invoked with -e
// I find it annoying to jump through hoops to get basic diagnostic information,
// so let's log it in any case:
if (buildContext != null) {
buildContext.addMessage(inputSpecFile, 0, 0, "unexpected error in Open-API generation", BuildContext.SEVERITY_WARNING, e);
}
getLog().error(e);
throw new MojoExecutionException(
"Code generation failed. See above for the full exception.");
}
}
View on GitHub (pinned to fcec517be3)
Solutions
- Check the parent path printed in the message: if a file occupies it, delete/rename the file and rerun.
- Ensure the build user has write permission on the whole output directory tree (chmod/chown, or fix the volume mount in Docker).
- Give each parallel execution its own <output> directory, or disable module-level parallelism for modules running this plugin.
- Run mvn clean to remove a stale directory structure before regenerating.
Defensive patterns
Strategy: validation
Validate before calling
# fail fast if the plugin output tree is not writable
OUT=$(mvn -q help:evaluate -Dexpression=openapi.output -DforceStdout 2>/dev/null || echo target/generated-sources)
mkdir -p "$OUT" 2>/dev/null || { echo "cannot create $OUT"; exit 1; }
[ -w "$OUT" ] || { echo "$OUT is not writable"; exit 1; } Prevention
- Ensure the build user owns the plugin <output> tree; avoid read-only mounts for generated sources.
- Do not check generated directories into git as read-only files.
- Give each parallel Maven execution (-T) its own output directory to avoid mkdirs races.
- Run mvn clean after restoring CI caches that may have replaced directories with files.
When it happens
Trigger: output directory on a read-only filesystem or one the build user cannot write; a file already exists where the directory should be (e.g. a stray file named like the folder); parallel Maven builds (mvn -T) racing two executions into the same output dir; container/CI environments with non-writable mounted volumes.
Common situations: Dockerized builds with a read-only or root-owned volume; CI caching that restored a file where the checksum directory belongs; highly parallel builds sharing one generated-sources directory; NFS/network mounts with flaky mkdir semantics.
Related errors
- Failed to generate .openapi-generator-ignore when the option
- Could not generate supporting file '{ignoreFileNameTarget}'
- Could not generate supporting file '{versionMetadata}'
- Target files must be generated within the output directory;
- Both %s and %s properties were set with different value.
AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22).
Data as JSON: /api/errors/c64edd65ebbd885c.
Report an issue: GitHub.