{"record":{"id":"80d3cccb4b64dff3","repo":"apache/maven","slug":"cannot-create-local-repository","errorCode":null,"errorMessage":"Cannot create local repository.","messagePattern":"Cannot create local repository\\.","errorType":"exception","errorClass":"MavenExecutionRequestPopulationException","httpStatus":null,"severity":"error","filePath":"impl/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java","lineNumber":139,"sourceCode":"            throws MavenExecutionRequestPopulationException {\n        String localRepositoryPath = null;\n\n        if (request.getLocalRepositoryPath() != null) {\n            localRepositoryPath = request.getLocalRepositoryPath().getAbsolutePath();\n        }\n\n        if (localRepositoryPath == null || localRepositoryPath.isEmpty()) {\n            String path = request.getUserProperties().getProperty(Constants.MAVEN_USER_CONF);\n            if (path == null) {\n                path = request.getSystemProperties().getProperty(\"user.home\") + File.separator + \".m2\";\n            }\n            localRepositoryPath = new File(path, \"repository\").getAbsolutePath();\n        }\n\n        try {\n            return repositorySystem.createLocalRepository(new File(localRepositoryPath));\n        } catch (Exception e) {\n            throw new MavenExecutionRequestPopulationException(\"Cannot create local repository.\", e);\n        }\n    }\n\n    private void baseDirectory(MavenExecutionRequest request) {\n        if (request.getBaseDirectory() == null && request.getPom() != null) {\n            request.setBaseDirectory(request.getPom().getAbsoluteFile().getParentFile());\n        }\n    }\n\n    /*if_not[MAVEN4]*/\n\n    @Override\n    @Deprecated\n    public MavenExecutionRequest populateFromSettings(MavenExecutionRequest request, Settings settings)\n            throws MavenExecutionRequestPopulationException {\n        if (settings == null) {\n            return request;\n        }","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java#L121-L157","documentation":"MavenExecutionRequestPopulationException thrown while deriving the local repository for a request. DefaultMavenExecutionRequestPopulator computes the path (maven.user.conf property, else ~/.m2/repository) and calls repositorySystem.createLocalRepository; ANY exception from that creation is wrapped as 'Cannot create local repository.' with no further detail in the message.","triggerScenarios":"populateFromSettings/populateDefaults on a request whose effective local repository path cannot be turned into a repository object: the path exists as a regular file, the directory cannot be created (permissions, read-only filesystem), or the path string is malformed.","commonSituations":"settings.xml <localRepository> pointing to a file or unwritable location; HOME/user.home unset or odd in containers so the ~/.m2 fallback resolves badly; CI agents with read-only home directories; overridden maven.user.conf property pointing somewhere invalid.","solutions":["Check settings.xml <localRepository>: it must be a creatable directory path, not an existing file","Verify the directory exists and is writable: mkdir -p <path> && touch <path>/.probe","Redirect to a known-good path for the run: mvn -Dmaven.repo.local=/tmp/repo ...","Ensure user.home resolves correctly (set HOME in Docker/CI) so the ~/.m2/repository fallback works"],"exampleFix":"<!-- before: points at a regular file or unwritable path -->\n<localRepository>/etc/maven/repo.txt</localRepository>\n\n<!-- after: creatable, writable directory -->\n<localRepository>/var/maven/repository</localRepository>","handlingStrategy":"validation","validationCode":"// Validate the local repository path before populating the request\nPath localRepo = Paths.get(effectiveLocalRepositoryPath); // from settings or default\nif (Files.exists(localRepo) && !Files.isDirectory(localRepo)) {\n    throw new IllegalStateException(\"localRepository path is a regular file: \" + localRepo);\n}\nFiles.createDirectories(localRepo);\nif (!Files.isWritable(localRepo)) {\n    throw new IllegalStateException(\"localRepository is not writable: \" + localRepo);\n}","typeGuard":null,"tryCatchPattern":"try {\n    popul.populateDefaults(request);\n} catch (MavenExecutionRequestPopulationException e) {\n    if (e.getMessage().equals(\"Cannot create local repository.\")) {\n        // the cause says why: permissions, path is a file, read-only FS\n        throw new IllegalStateException(\"Fix settings.xml <localRepository>: \" + localRepoPath, e.getCause());\n    }\n    throw e;\n}","preventionTips":["Keep <localRepository> as a dedicated, writable directory","Set HOME explicitly in containers so the ~/.m2 fallback resolves","Probe local-repo writability in CI bootstrap steps"],"tags":["maven","local-repository","settings-xml","file-permissions"],"backgroundTag":"local-repository-unavailable","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}