{"record":{"id":"dbef1629217429bb","repo":"apache/maven","slug":"unable-to-find-the-root-directory-create-a-mvn-d-dbef16","errorCode":null,"errorMessage":"Unable to find the root directory. Create a .mvn directory in the root directory or add the root=\"true\" attribute on the root project's model to identify it.","messagePattern":"Unable to find the root directory\\. Create a \\.mvn directory in the root directory or add the root=\"true\" attribute on the root project's model to identify it\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"impl/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java","lineNumber":1171,"sourceCode":"        return this;\n    }\n\n    @Deprecated\n    @Override\n    public void setMultiModuleProjectDirectory(File directory) {\n        this.multiModuleProjectDirectory = directory;\n    }\n\n    @Deprecated\n    @Override\n    public File getMultiModuleProjectDirectory() {\n        return multiModuleProjectDirectory;\n    }\n\n    @Override\n    public Path getRootDirectory() {\n        if (rootDirectory == null) {\n            throw new IllegalStateException(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE);\n        }\n        return rootDirectory;\n    }\n\n    @Override\n    public MavenExecutionRequest setRootDirectory(Path rootDirectory) {\n        this.rootDirectory = rootDirectory;\n        return this;\n    }\n\n    @Override\n    public Path getTopDirectory() {\n        return topDirectory;\n    }\n\n    @Override\n    public MavenExecutionRequest setTopDirectory(Path topDirectory) {\n        this.topDirectory = topDirectory;","sourceCodeStart":1153,"sourceCodeEnd":1189,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java#L1153-L1189","documentation":"IllegalStateException from MavenExecutionRequest.getRootDirectory() when the request was never given a root directory. Maven locates the root of a multi-module build by scanning upward for a .mvn directory or a pom with root=\"true\"; DefaultMavenExecutionRequest only stores the result and throws this constant message (RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE) if nothing was found and no value was set.","triggerScenarios":"Calling getRootDirectory() on a request where setRootDirectory(...) was never invoked and directory scanning found no .mvn directory and no root=\"true\" pom. Typical when embedding Maven (embedder, maven-invoker, tests) and constructing DefaultMavenExecutionRequest by hand instead of via the CLI locator.","commonSituations":"Embedders/tests building requests directly; projects that deleted the .mvn directory; tools assuming every pom hierarchy has a discoverable root; running Maven from inside an unmarked directory tree.","solutions":["Create a .mvn directory at the repository root (an empty one is enough)","Or mark the root pom with <project ... root=\"true\">","When building requests programmatically, call request.setRootDirectory(Paths.get(...)) before anything reads it, or run the request through MavenExecutionRequestPopulator/RootLocator","Guard call sites with try/catch IllegalStateException if absence is legitimate in your tool"],"exampleFix":"// before\nMavenExecutionRequest request = new DefaultMavenExecutionRequest();\nPath root = request.getRootDirectory(); // IllegalStateException\n\n// after\nMavenExecutionRequest request = new DefaultMavenExecutionRequest();\nrequest.setRootDirectory(Paths.get(\"/repo/root\")); // or populate via RootLocator\nPath root = request.getRootDirectory();","handlingStrategy":"try-catch","validationCode":"// Locate the root the same way Maven does, before touching getRootDirectory()\nPath dir = Paths.get(request.getBaseDirectory());\nPath root = dir;\nwhile (root != null && !Files.exists(root.resolve(\".mvn\"))) {\n    root = root.getParent();\n}\nif (root != null) {\n    request.setRootDirectory(root);\n}","typeGuard":null,"tryCatchPattern":"try {\n    Path root = request.getRootDirectory();\n} catch (IllegalStateException e) {\n    // no .mvn and no root=\"true\" pom above the cwd\n    throw new IllegalStateException(\"Add a .mvn directory at the repo root or set root=\\\"true\\\" on the root pom\", e);\n}","preventionTips":["Commit a .mvn directory (can hold maven.config/jvm.config) at every repo root","Embedders: populate requests via MavenExecutionRequestPopulator plus RootLocator instead of manual construction","Never assume getRootDirectory() succeeds on hand-built requests"],"tags":["maven","multi-module","root-directory","embedder","maven-execution-request"],"backgroundTag":"missing-root-directory-marker","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}