{"record":{"id":"7141cf50adf2b33e","repo":"apache/maven","slug":"n-tartifact-retains-local-artifactscope-o","errorCode":null,"errorMessage":"\\n\\tArtifact {} retains local artifactScope '{}' overriding broader artifactScope '{}'\\n\\tgiven by a dependency. If this is not intended, modify or remove the local artifactScope.\\n","messagePattern":"\\\\n\\\\tArtifact (.+?) retains local artifactScope '(.+?)' overriding broader artifactScope '(.+?)'\\\\n\\\\tgiven by a dependency\\. If this is not intended, modify or remove the local artifactScope\\.\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"compat/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java","lineNumber":85,"sourceCode":"\n        if (!Objects.equals(omittedVersion, keptVersion)) {\n            logger.debug(indent + omitted + \" (removed - nearer found: \" + keptVersion + \")\");\n        }\n    }\n\n    @Override\n    public void omitForCycle(Artifact omitted) {\n        logger.debug(indent + omitted + \" (removed - causes a cycle in the graph)\");\n    }\n\n    @Override\n    public void updateScopeCurrentPom(Artifact artifact, String ignoredScope) {\n        logger.debug(indent + artifact + \" (not setting artifactScope to: \" + ignoredScope + \"; local artifactScope \"\n                + artifact.getScope() + \" wins)\");\n\n        // TODO better way than static? this might hide messages in a reactor\n        if (!ignoredArtifacts.contains(artifact)) {\n            logger.warn(\"\\n\\tArtifact \" + artifact + \" retains local artifactScope '\" + artifact.getScope()\n                    + \"' overriding broader artifactScope '\" + ignoredScope + \"'\\n\"\n                    + \"\\tgiven by a dependency. If this is not intended, modify or remove the local artifactScope.\\n\");\n            ignoredArtifacts.add(artifact);\n        }\n    }\n\n    @Override\n    public void updateScope(Artifact artifact, String scope) {\n        logger.debug(indent + artifact + \" (setting artifactScope to: \" + scope + \")\");\n    }\n\n    @Override\n    public void selectVersionFromRange(Artifact artifact) {\n        logger.debug(indent + artifact + \" (setting version to: \" + artifact.getVersion() + \" from range: \"\n                + artifact.getVersionRange() + \")\");\n    }\n\n    @Override","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/compat/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java#L67-L103","documentation":"Warning from DebugResolutionListener.updateScopeCurrentPom during dependency resolution: a dependency declared directly in the current POM keeps its locally declared scope even though a transitive path would assign it a broader (e.g. compile) scope. Maven's resolution keeps the direct declaration; the listener warns once per artifact (tracked via the static ignoredArtifacts set) because the local scope overrides what the dependency graph requested.","triggerScenarios":"A POM declares <dependency> with scope test (or provided/runtime) while the same artifact is also reachable transitively with compile scope from another dependency; during conflict resolution updateScopeCurrentPom fires and logs this warning. Typical example: junit declared test but also dragged in compile-scope by a framework dependency.","commonSituations":"Test-only artifacts leaking into compile scope via framework dependencies; intentional narrowing (declaring provided to exclude from war) that surprises teammates; upgrading a library that newly exposes a transitive dependency you also declare.","solutions":["Run mvn dependency:tree -Dverbose and locate the artifact to see both the direct declaration and the transitive path that wants the broader scope.","If the narrower local scope is intended (usual case), ignore the warning or document it in the POM.","If not intended, change the local <scope> to match what you actually need at runtime.","Alternatively exclude the artifact from the dependency that pulls it with the broader scope.","Note the check uses a static set: in a multi-module reactor the warning may be suppressed for repeated artifacts across modules."],"exampleFix":"<!-- before -->\n<dependency>\n  <groupId>junit</groupId>\n  <artifactId>junit</artifactId>\n  <scope>test</scope>\n</dependency>\n<!-- after (warning is informational; confirm intent with) -->\nmvn dependency:tree -Dverbose -Dincludes=junit:junit","handlingStrategy":"validation","validationCode":"mvn dependency:tree -Dverbose -Dincludes=<group>:<artifact> # run in CI and fail on unexpected scope conflicts","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Review dependency:tree -Dverbose output when adding direct test-scope dependencies.","Prefer <exclusions> on the offender if the narrower scope must hold.","Document intentional scope narrowing in the POM so the warn is understood."],"tags":["maven","dependency-resolution","scope","pom"],"backgroundTag":"dependency-scope-override","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}