{"record":{"id":"bb03a168721286c4","repo":"apache/maven","slug":"cannot-find-artifactrepositorylayout-instance-for","errorCode":null,"errorMessage":"Cannot find ArtifactRepositoryLayout instance for: \" + layoutId","messagePattern":"Cannot find ArtifactRepositoryLayout instance for: \" \\+ layoutId","errorType":"exception","errorClass":"UnknownRepositoryLayoutException","httpStatus":null,"severity":"error","filePath":"compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/repository/DefaultArtifactRepositoryFactory.java","lineNumber":66,"sourceCode":"    @Override\n    public ArtifactRepositoryLayout getLayout(String layoutId) throws UnknownRepositoryLayoutException {\n        return repositoryLayouts.get(layoutId);\n    }\n\n    @Override\n    public ArtifactRepository createDeploymentArtifactRepository(\n            String id, String url, String layoutId, boolean uniqueVersion) throws UnknownRepositoryLayoutException {\n        ArtifactRepositoryLayout layout = repositoryLayouts.get(layoutId);\n\n        checkLayout(id, layoutId, layout);\n\n        return createDeploymentArtifactRepository(id, url, layout, uniqueVersion);\n    }\n\n    private void checkLayout(String repositoryId, String layoutId, ArtifactRepositoryLayout layout)\n            throws UnknownRepositoryLayoutException {\n        if (layout == null) {\n            throw new UnknownRepositoryLayoutException(repositoryId, layoutId);\n        }\n    }\n\n    @Override\n    public ArtifactRepository createDeploymentArtifactRepository(\n            String id, String url, ArtifactRepositoryLayout repositoryLayout, boolean uniqueVersion) {\n        return createArtifactRepository(id, url, repositoryLayout, null, null);\n    }\n\n    @Override\n    public ArtifactRepository createArtifactRepository(\n            String id,\n            String url,\n            String layoutId,\n            ArtifactRepositoryPolicy snapshots,\n            ArtifactRepositoryPolicy releases)\n            throws UnknownRepositoryLayoutException {\n        ArtifactRepositoryLayout layout = repositoryLayouts.get(layoutId);","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/repository/DefaultArtifactRepositoryFactory.java#L48-L84","documentation":"DefaultArtifactRepositoryFactory.createDeploymentArtifactRepository(id, url, layoutId, uniqueVersion) looks the layoutId up in a map of ArtifactRepositoryLayout components wired from the Plexus container. Only the built-in hints 'default' and 'legacy' are registered out of the box; any other id fails the lookup and is reported as UnknownRepositoryLayoutException('Cannot find ArtifactRepositoryLayout instance for: <layoutId>'). The exception is a subclass of InvalidRepositoryException and also carries the offending layoutId via getLayoutId().","triggerScenarios":"Calling createDeploymentArtifactRepository with a layoutId other than \"default\" or \"legacy\" when no custom ArtifactRepositoryLayout component is registered under that role hint in the container; or a custom layout that used to be contributed by an extension/plugin that is no longer on the build classpath.","commonSituations":"Maven 2-era deployment code passing a homegrown layout id; typos like \"defaults\" or \"maven-default\" instead of \"default\"; uninstalling or renaming a third-party repository-layout extension while old configuration still references its hint.","solutions":["Use the built-in layout id \"default\" (Maven 2/3 standard layout) unless you specifically need the Maven 1 \"legacy\" layout","Check the exact hint via UnknownRepositoryLayoutException.getLayoutId() and fix typos in the caller","If a custom layout is genuinely required, register an ArtifactRepositoryLayout component with a matching @Named/hint in the container (or as a Plexus/SI component in an extension)","Prefer the overload createDeploymentArtifactRepository(id, url, ArtifactRepositoryLayout, uniqueVersion) and pass the layout instance directly, avoiding the string lookup entirely"],"exampleFix":"// before\nArtifactRepository repo = factory.createDeploymentArtifactRepository(\n    \"releases\", \"https://repo.example.com/releases\", \"maven-default\", true);\n\n// after\nArtifactRepository repo = factory.createDeploymentArtifactRepository(\n    \"releases\", \"https://repo.example.com/releases\", \"default\", true);","handlingStrategy":"validation","validationCode":"import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;\n\nprivate static final Set<String> BUILT_IN_LAYOUTS = Set.of(\"default\", \"legacy\");\n\nvoid requireKnownLayout(String layoutId) throws UnknownRepositoryLayoutException {\n    if (layoutId == null || !BUILT_IN_LAYOUTS.contains(layoutId)\n            || repositoryLayouts.get(layoutId) == null) {\n        throw new UnknownRepositoryLayoutException(repositoryId, layoutId);\n    }\n}\n// or skip the string lookup entirely:\nfactory.createDeploymentArtifactRepository(id, url, defaultLayout /* instance */, true);","typeGuard":null,"tryCatchPattern":"try {\n    ArtifactRepository repo = factory.createDeploymentArtifactRepository(id, url, layoutId, true);\n} catch (UnknownRepositoryLayoutException e) {\n    String badLayout = e.getLayoutId(); // exact failing hint\n    log.error(\"Layout '{}' is not registered; falling back to 'default'\", badLayout);\n    repo = factory.createDeploymentArtifactRepository(id, url, \"default\", true);\n}","preventionTips":["Default to the 'default' layout unless a concrete requirement demands otherwise","Centralize the layout id in one constant so typos cannot spread across call sites","If you rely on a custom layout component, add a smoke test that looks it up in the container at build startup"],"tags":["maven","repository","layout","plexus","component-lookup","legacy-compat"],"backgroundTag":"unknown-provider-id","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}