{"record":{"id":"6bef9dfd4de016ba","repo":"apache/maven","slug":"duplicate-dependency","errorCode":null,"errorMessage":"Duplicate dependency: {}","messagePattern":"Duplicate dependency: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java","lineNumber":298,"sourceCode":"            model = model.withDependencies(directDependencies.isEmpty() ? null : directDependencies.values());\n        }\n\n        return model;\n    }\n\n    private static boolean hasDependencyScope(Dependency dependency) {\n        String scopeId = dependency.getScope();\n        DependencyScope scope;\n        if (scopeId == null || scopeId.isEmpty()) {\n            scope = DependencyScope.COMPILE;\n        } else {\n            scope = DependencyScope.forId(scopeId);\n        }\n        return scope == null || !scope.isTransitive();\n    }\n\n    private Dependency merge(Dependency dep1, Dependency dep2) {\n        throw new IllegalArgumentException(\"Duplicate dependency: \" + getDependencyKey(dep1));\n    }\n\n    private static String getDependencyKey(org.apache.maven.api.Dependency dependency) {\n        return dependency.getGroupId() + \":\" + dependency.getArtifactId() + \":\"\n                + dependency.getType().id() + \":\" + dependency.getClassifier();\n    }\n\n    private static String getDependencyKey(Dependency dependency) {\n        return dependency.getGroupId() + \":\" + dependency.getArtifactId() + \":\"\n                + (dependency.getType() != null ? dependency.getType() : \"jar\") + \":\"\n                + (dependency.getClassifier() != null ? dependency.getClassifier() : \"\");\n    }\n\n    private ModelBuilderResult buildModel(RepositorySystemSession session, MavenProject project, ModelSource src)\n            throws ModelBuilderException {\n        InternalSession iSession = InternalSession.from(session);\n        ModelBuilderRequest.ModelBuilderRequestBuilder request = ModelBuilderRequest.builder();\n        request.requestType(ModelBuilderRequest.RequestType.BUILD_CONSUMER);","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java#L280-L316","documentation":"During consumer POM construction, DependencyMerger calls merge() when the same dependency key (groupId:artifactId:type:classifier) appears in a context where duplicates must be reconciled — the default strategy is to treat duplicates as an error, so merge() unconditionally throws IllegalArgumentException naming the duplicated key.","triggerScenarios":"A POM (or effective POM after parent merge) containing two <dependency> entries with the same groupId:artifactId:type:classifier — e.g. the same GAV declared with two different versions/scopes, or a dependency repeated once directly and once via a profile that is active, hitting the merge path in DefaultConsumerPomBuilder.","commonSituations":"Copy-pasting a dependency and editing only the version; declaring the same artifact in both compile and test scope instead of using <exclusions> or dependencyManagement; profile-activated duplicates (dev vs default profiles both on); parent and child both declaring the same dependency with different classifiers resolved to the same key.","solutions":["Search the POM (and active profiles/parents) for the groupId:artifactId:type:classifier printed in the message and delete one of the entries","If you need one version everywhere, declare it once in <dependencyManagement> and reference it without the version","Check active profiles ('mvn help:active-profiles') — a dependency enabled by two profiles at once is a common source","Re-run 'mvn help:effective-pom' to confirm only one entry survives after the fix"],"exampleFix":"<!-- before -->\n<dependency><groupId>org.acme</groupId><artifactId>lib</artifactId><version>1.0</version></dependency>\n<dependency><groupId>org.acme</groupId><artifactId>lib</artifactId><version>2.0</version></dependency>\n\n<!-- after -->\n<dependency><groupId>org.acme</groupId><artifactId>lib</artifactId><version>2.0</version></dependency>","handlingStrategy":"validation","validationCode":"// lint the POM before building: no two deps share groupId:artifactId:type:classifier\nSet<String> keys = new HashSet<>();\nfor (Dependency d : model.getDependencies()) {\n    if (!keys.add(d.getGroupId() + \":\" + d.getArtifactId() + \":\" + d.getType() + \":\" + d.getClassifier())) {\n        throw new IllegalArgumentException(\"Duplicate dependency: \" + d);\n    }\n}","typeGuard":null,"tryCatchPattern":"catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Duplicate dependency:\")) {\n        // remove the duplicate entry printed in the message, re-run\n    }\n}","preventionTips":["Let dependencyManagement own versions; declare each dependency exactly once","Audit active profiles that add dependencies overlapping the main list","Use 'mvn help:effective-pom' to spot duplicates before install/deploy"],"tags":["maven","consumer-pom","duplicate-dependency","pom-validation"],"backgroundTag":"duplicate-dependency-declared","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}