apache/maven · warning

Unknown cache scope: {}, using default REQUEST_SCOPED

Error message

Unknown cache scope: {}, using default REQUEST_SCOPED

What it means

The 'scope' key of a cache selector configuration was parsed and its value (lower-cased) matched none of session, request, persistent, disabled, or none. CacheSelectorParser.parseScope() logs the raw value and yields the default CacheRetention.REQUEST_SCOPED, so the cache for that selector is request-scoped regardless of what was intended. The build continues; only cache retention differs from the requested one.

Source

Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/cache/CacheSelectorParser.java:140

                    LOGGER.warn("Unknown cache configuration property: {}", key);
            }
        }

        // Return partial configuration (null values are allowed)
        return new PartialCacheConfig(scope, referenceType);
    }

    /**
     * Parses a scope string into CacheRetention.
     */
    private static CacheRetention parseScope(String value) {
        return switch (value.toLowerCase(Locale.ENGLISH)) {
            case "session" -> CacheRetention.SESSION_SCOPED;
            case "request" -> CacheRetention.REQUEST_SCOPED;
            case "persistent" -> CacheRetention.PERSISTENT;
            case "disabled", "none" -> CacheRetention.DISABLED;
            default -> {
                LOGGER.warn("Unknown cache scope: {}, using default REQUEST_SCOPED", value);
                yield CacheRetention.REQUEST_SCOPED;
            }
        };
    }

    /**
     * Parses a reference type string into Cache.ReferenceType.
     */
    private static Cache.ReferenceType parseReferenceType(String value) {
        return switch (value.toLowerCase(Locale.ENGLISH)) {
            case "soft" -> Cache.ReferenceType.SOFT;
            case "hard" -> Cache.ReferenceType.HARD;
            case "weak" -> Cache.ReferenceType.WEAK;
            case "none" -> Cache.ReferenceType.NONE;
            default -> {
                LOGGER.warn("Unknown reference type: {}, using default SOFT", value);
                yield Cache.ReferenceType.SOFT;
            }

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Use one of the accepted scope values: session, request, persistent, or disabled/none
  2. If you wanted caching to survive the build, use scope=persistent
  3. Re-run and confirm the warning is gone, otherwise your selector block may also contain unknown keys (see the unknown-property warning)

Example fix

# before
mvn clean install '-Dmaven.cache.config=**{scope=global}'

# after
mvn clean install '-Dmaven.cache.config=**{scope=persistent}'
Defensive patterns

Strategy: validation

Validate before calling

// Mirror the parser's vocabulary and reject invalid scope values up front
static final Set<String> VALID_SCOPES =
        Set.of("session", "request", "persistent", "disabled", "none");
String scope = kv.get("scope");
if (scope != null && !VALID_SCOPES.contains(scope.trim().toLowerCase(Locale.ROOT))) {
    throw new IllegalArgumentException(
        "cache scope must be session|request|persistent|disabled|none, got: " + scope);
}

Type guard

Optional<CacheRetention> asCacheScope(String s) {
    if (s == null) return Optional.empty();
    return switch (s.trim().toLowerCase(Locale.ROOT)) {
        case "session" -> Optional.of(CacheRetention.SESSION_SCOPED);
        case "request" -> Optional.of(CacheRetention.REQUEST_SCOPED);
        case "persistent" -> Optional.of(CacheRetention.PERSISTENT);
        case "disabled", "none" -> Optional.of(CacheRetention.DISABLED);
        default -> Optional.empty();
    };
}

Prevention

When it happens

Trigger: -Dmaven.cache.config=<selector>{scope=<bad>} with <bad> e.g. 'global', 'jvm', 'application', 'singleton', or a trailing-space variant that survives trim (none: trim happens before parse, so plain typos are the usual case).

Common situations: Users expecting a cross-build ('persistent') cache typing scope=global; migration from another build tool's cache terminology; sharing config snippets between machines with different Maven versions where the scope vocabulary changed.

Related errors


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