quarkusio/quarkus · error · IllegalStateException
No <project> in file [<pomXmlPath>]
Error message
No <project> in file [<pomXmlPath>]
What it means
PomTransformer.addModule throws IllegalStateException 'No <project> in file [<pomXmlPath>]' when, after failing to locate an existing <build> element, XPath evaluation cannot find a <project> root element in the parsed pom DOM. addModule needs the project root to insert a <build><modules> hierarchy.
Source
Thrown at independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/PomTransformer.java:278
final Node modulesIndent = context.indent(1);
modules = document.createElement("modules");
modules.appendChild(context.indent(1));
final Node build = (Node) context.getXPath().evaluate(anyNs("project", "build"), document,
XPathConstants.NODE);
if (build != null) {
Node ws = build.getPreviousSibling();
if (ws == null || ws.getNodeType() != Node.TEXT_NODE) {
ws = context.indent(1);
build.getParentNode().insertBefore(ws, build);
}
build.getParentNode().insertBefore(modulesIndent, ws);
build.getParentNode().insertBefore(modules, ws);
} else {
final Node project = (Node) context.getXPath().evaluate(anyNs("project"), document,
XPathConstants.NODE);
if (project == null) {
throw new IllegalStateException(
String.format("No <project> in file [%s]", context.getPomXmlPath()));
}
final NodeList projectChildren = project.getChildNodes();
final int len = projectChildren.getLength();
Node ws = null;
if (len == 0 || (ws = projectChildren.item(len - 1)).getNodeType() != Node.TEXT_NODE) {
ws = document.createTextNode("\n");
project.appendChild(ws);
}
project.insertBefore(modulesIndent, ws);
project.insertBefore(modules, ws);
}
}
final Node moduleNode = document.createElement("module");
moduleNode.appendChild(document.createTextNode(module));
final NodeList modulesChildren = modules.getChildNodes();View on GitHub (pinned to e1c734241f)
Solutions
- Verify the target file is a valid pom.xml with a <project> root
- Check the file is not empty or truncated
- If building poms programmatically, ensure the template contains <project xmlns="http://maven.apache.org/POM/4.0.0">
- Point the transformer at the correct path (the module pom, not settings.xml or another XML)
Example fix
// before
String template = "<?xml version=\"1.0\"?>\n<foo/>"; // wrong root
transformer.addModule("../shared-lib");
// after
String template = "<?xml version=\"1.0\"?>\n<project xmlns=\"http://maven.apache.org/POM/4.0.0\"></project>";
transformer.addModule("../shared-lib"); Defensive patterns
Strategy: validation
Validate before calling
String src = Files.readString(pomPath);
if (!src.contains("<project")) {
throw new IllegalStateException("File is not a pom (no <project> root): " + pomPath);
} Try / catch
try {
transformer.addModule("../shared-lib");
} catch (IllegalStateException e) {
if (e.getMessage() != null && e.getMessage().startsWith("No <project>")) {
throw new IllegalStateException("Target file lacks <project> root: " + pomPath, e);
}
throw e;
} Prevention
- Confirm the file has a <project> root before invoking addModule
- Never point PomTransformer at settings.xml or other non-pom XML
- Keep pom templates complete (with namespaced project element) when generating projects
- Check for empty/truncated poms after code generation steps
When it happens
Trigger: Calling addModule(...) on a parsed document whose root is not <project> (any namespace handling aside) — e.g. the file is empty, is not a pom (settings.xml, wrong XML), or the DOM was built from a source that lacks a project element.
Common situations: Pointing the transformer at a non-pom XML file, an empty/truncated pom, or a pom with an unexpected root element name/namespace after templating.
Related errors
- Unable to parse pom file: ${pom}
- Could not resolve POM for
- Unable to update the pom.xml file
- The parent project must have a packaging type of POM. Curren
- Unable to update the pom.xml file
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/d34a2ce61184642b.
Report an issue: GitHub.