quarkusio/quarkus · error · MojoExecutionException
Failed to locate element <name>
Error message
Failed to locate element <name>
What it means
CreateUtils.getElement scans a NodeList for an element matching the given local/node name. If no matching ELEMENT_NODE is found after iterating all children, it throws a MojoExecutionException 'Failed to locate element <name>'. It is a strict lookup: the caller (e.g. pluginNode, node) expects a structurally required element.
Source
Thrown at devtools/maven/src/main/java/io/quarkus/maven/CreateUtils.java:94
private static String getChildElementTextValue(final Node parentNode, String childName) throws MojoExecutionException {
final Node node = getElement(parentNode.getChildNodes(), childName);
final String text = getText(node);
if (text.isEmpty()) {
throw new MojoExecutionException(
"The " + parentNode.getNodeName() + " element description is missing child " + childName);
}
return text;
}
private static Node getElement(NodeList nodeList, String name) throws MojoExecutionException {
for (int i = 0; i < nodeList.getLength(); ++i) {
final Node item = nodeList.item(i);
if (item.getNodeType() == Node.ELEMENT_NODE
&& (name.equals(item.getNodeName()) || name.equals(item.getLocalName()))) {
return item;
}
}
throw new MojoExecutionException("Failed to locate element " + name);
}
private static String getText(Node node) {
if (!node.hasChildNodes()) {
return "";
}
StringBuffer result = new StringBuffer();
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node subnode = list.item(i);
if (subnode.getNodeType() == Node.TEXT_NODE) {
result.append(subnode.getNodeValue());
} else if (subnode.getNodeType() == Node.CDATA_SECTION_NODE) {
result.append(subnode.getNodeValue());
} else if (subnode.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
// Recurse into the subtree for text
// (and ignore comments)
result.append(getText(subnode));View on GitHub (pinned to e1c734241f)
Solutions
- Add the missing element with the exact expected name to the XML document
- Check for namespace issues — the element must match getNodeName() or getLocalName()
- Validate the document structure against a known-good working example (e.g. from a freshly generated project)
Example fix
// before <pluginInfo> <!-- <description> missing --> </pluginInfo> // after <pluginInfo> <description>My plugin description</description> </pluginInfo>
Defensive patterns
Strategy: validation
Validate before calling
// Check required elements exist before running the goal
var doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(pomFile);
var required = java.util.List.of("expectedElementName");
for (String name : required) {
if (doc.getElementsByTagName(name).getLength() == 0) {
throw new IllegalStateException("Missing required element <" + name + ">");
}
} Type guard
static boolean containsElement(Node parent, String name) {
var nodes = parent.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node n = nodes.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE
&& (name.equals(n.getNodeName()) || name.equals(n.getLocalName()))) {
return true;
}
}
return false;
} Try / catch
try {
mojo.execute();
} catch (MojoExecutionException e) {
if (e.getMessage().startsWith("Failed to locate element")) {
String element = e.getMessage().substring(e.getMessage().lastIndexOf(' ') + 1);
// add the missing element <element> to the document and re-run
}
} Prevention
- Keep project descriptors structurally identical to freshly generated reference projects
- Verify XML namespaces when documents use namespace-qualified elements
- Diff your descriptor against a working one after upgrades or migrations
When it happens
Trigger: Calling a Quarkus Maven create-style goal whose resolvePluginInfo path invokes getElement (directly or via getChildElementTextValue/pluginNode) on an XML document that lacks the required element entirely.
Common situations: pom.xml or plugin descriptor missing an expected element after manual edits or an upgrade; wrong namespace so getLocalName() does not match; typos in element names; XML malformed or an entirely different document passed for parsing.
Related errors
- The <parentNodeName> element description is missing child <c
- Unable to parse pom file: ${pom}
- Failed to build enhanced artifact
- Failed to build quarkus application
- Failed to parse <pluginXml>
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/c4a408b46d9b901e.
Report an issue: GitHub.