{"record":{"id":"b55456ca55480fb8","repo":"apache/maven","slug":"could-not-create-local-repository-at","errorCode":null,"errorMessage":"Could not create local repository at {}","messagePattern":"Could not create local repository at (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"impl/maven-core/src/main/java/org/apache/maven/DefaultMaven.java","lineNumber":445,"sourceCode":"        return result;\n    }\n\n    private CloseableSession newCloseableSession(MavenExecutionRequest request, WorkspaceReader workspaceReader) {\n        return repositorySessionFactory\n                .newRepositorySessionBuilder(request)\n                .setWorkspaceReader(workspaceReader)\n                .build();\n    }\n\n    private void validateLocalRepository(MavenExecutionRequest request) throws IOException {\n        File localRepoDir = request.getLocalRepositoryPath();\n\n        logger.debug(\"Using local repository at {}\", localRepoDir);\n\n        localRepoDir.mkdirs();\n\n        if (!localRepoDir.isDirectory()) {\n            throw new IOException(\"Could not create local repository at \" + localRepoDir);\n        }\n    }\n\n    private <T> Collection<T> getExtensionComponents(Collection<MavenProject> projects, Class<T> role) {\n        Collection<T> foundComponents = new LinkedHashSet<>();\n        foundComponents.addAll(lookup.lookupList(role));\n        foundComponents.addAll(getProjectScopedExtensionComponents(projects, role));\n        return foundComponents;\n    }\n\n    protected <T> Collection<T> getProjectScopedExtensionComponents(Collection<MavenProject> projects, Class<T> role) {\n        if (projects == null) {\n            return Collections.emptyList();\n        }\n\n        Collection<T> foundComponents = new LinkedHashSet<>();\n        Collection<ClassLoader> scannedRealms = new HashSet<>();\n","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-core/src/main/java/org/apache/maven/DefaultMaven.java#L427-L463","documentation":"Before building, DefaultMaven.validateLocalRepository mkdirs() the local repository path (from settings.xml localRepository or -Dmaven.repo.local) and throws IOException if the path is still not a directory afterwards. mkdirs silently fails when a regular file occupies the path, a parent is not writable, the filesystem is read-only, or permissions deny creation. The message names the path.","triggerScenarios":"-Dmaven.repo.local=/some/path where /some/path or a parent lacks write permission; a file (not directory) already exists at the path; read-only container mounts; SELinux/AppArmor denials; disk full.","commonSituations":"CI containers running as non-root against root-owned volumes; Docker mounts of ~/.m2 with mismatched uid; a typo'd earlier command creating a file where the repo dir should be; locked-down corporate images.","solutions":["Inspect the path: `ls -ld <path>` - if a file occupies it, remove/move it and rerun.","Grant write+execute on the directory and all parents for the build user, or choose a writable path via -Dmaven.repo.local or settings.xml.","In containers, mount the repo volume with matching uid/gid or run with `--user $(id -u):$(id -g)`.","Check disk space (`df -h <path>`) and whether the mount is read-only (`mount | grep <path>`)."],"exampleFix":"# before: a regular file blocks the repository directory\n$ ls -ld /repo\n-rw-r--r-- 1 root root 0 /repo\n\n# after\n$ rm /repo && mvn -Dmaven.repo.local=/repo package","handlingStrategy":"validation","validationCode":"File repo = request.getLocalRepositoryPath();\nif (repo.exists() ? !repo.isDirectory() || !repo.canWrite() : !repo.getAbsoluteFile().getParentFile().canWrite()) {\n    throw new IOException(\"Local repository path not usable (file in the way or not writable): \" + repo);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set an explicit writable -Dmaven.repo.local in containers instead of relying on defaults.","Run containers with `--user $(id -u):$(id -g)` when bind-mounting the repo.","Never let other tooling create a plain file where the repo directory belongs."],"tags":["maven","local-repository","filesystem","permissions"],"backgroundTag":"local-repository-not-writable","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}