apache/maven · warning

\n\tArtifact {} retains local artifactScope '{}' overriding

Error message

\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

What it means

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.

Source

Thrown at compat/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java:85

        if (!Objects.equals(omittedVersion, keptVersion)) {
            logger.debug(indent + omitted + " (removed - nearer found: " + keptVersion + ")");
        }
    }

    @Override
    public void omitForCycle(Artifact omitted) {
        logger.debug(indent + omitted + " (removed - causes a cycle in the graph)");
    }

    @Override
    public void updateScopeCurrentPom(Artifact artifact, String ignoredScope) {
        logger.debug(indent + artifact + " (not setting artifactScope to: " + ignoredScope + "; local artifactScope "
                + artifact.getScope() + " wins)");

        // TODO better way than static? this might hide messages in a reactor
        if (!ignoredArtifacts.contains(artifact)) {
            logger.warn("\n\tArtifact " + artifact + " retains local artifactScope '" + artifact.getScope()
                    + "' overriding broader artifactScope '" + ignoredScope + "'\n"
                    + "\tgiven by a dependency. If this is not intended, modify or remove the local artifactScope.\n");
            ignoredArtifacts.add(artifact);
        }
    }

    @Override
    public void updateScope(Artifact artifact, String scope) {
        logger.debug(indent + artifact + " (setting artifactScope to: " + scope + ")");
    }

    @Override
    public void selectVersionFromRange(Artifact artifact) {
        logger.debug(indent + artifact + " (setting version to: " + artifact.getVersion() + " from range: "
                + artifact.getVersionRange() + ")");
    }

    @Override

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Run mvn dependency:tree -Dverbose and locate the artifact to see both the direct declaration and the transitive path that wants the broader scope.
  2. If the narrower local scope is intended (usual case), ignore the warning or document it in the POM.
  3. If not intended, change the local <scope> to match what you actually need at runtime.
  4. Alternatively exclude the artifact from the dependency that pulls it with the broader scope.
  5. Note the check uses a static set: in a multi-module reactor the warning may be suppressed for repeated artifacts across modules.

Example fix

<!-- before -->
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <scope>test</scope>
</dependency>
<!-- after (warning is informational; confirm intent with) -->
mvn dependency:tree -Dverbose -Dincludes=junit:junit
Defensive patterns

Strategy: validation

Validate before calling

mvn dependency:tree -Dverbose -Dincludes=<group>:<artifact> # run in CI and fail on unexpected scope conflicts

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/7141cf50adf2b33e. Report an issue: GitHub.