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

  1. Verify the target file is a valid pom.xml with a <project> root
  2. Check the file is not empty or truncated
  3. If building poms programmatically, ensure the template contains <project xmlns="http://maven.apache.org/POM/4.0.0">
  4. 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

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


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/d34a2ce61184642b. Report an issue: GitHub.