apache/maven · error · IllegalArgumentException

{} is not a valid log severity threshold. Valid severities a

Error message

{} is not a valid log severity threshold. Valid severities are WARN/WARNING and ERROR.

What it means

The --fail-on-severity / --fos option asks Maven to fail the build when log output reaches a given severity. MavenCli validates the argument against a fixed switch accepting only 'warn', 'warning', and 'error' (case-insensitive via toLowerCase(Locale.ENGLISH)); anything else throws IllegalArgumentException. The validation only runs when the active SLF4J factory implements LogLevelRecorder (Maven's built-in maven-slf4j-provider does); with an external binding (logback, log4j, etc.) the flag is instead ignored with a warning and no exception is thrown.

Source

Thrown at compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java:582

                //
            }
        }

        slf4jConfiguration.activate();

        plexusLoggerManager = new Slf4jLoggerManager();
        slf4jLogger = slf4jLoggerFactory.getLogger(this.getClass().getName());

        if (commandLine.hasOption(CLIManager.FAIL_ON_SEVERITY)) {
            String logLevelThreshold = commandLine.getOptionValue(CLIManager.FAIL_ON_SEVERITY);

            if (slf4jLoggerFactory instanceof LogLevelRecorder recorder) {
                LogLevelRecorder.Level level =
                        switch (logLevelThreshold.toLowerCase(Locale.ENGLISH)) {
                            case "warn", "warning" -> LogLevelRecorder.Level.WARN;
                            case "error" -> LogLevelRecorder.Level.ERROR;
                            default ->
                                throw new IllegalArgumentException(
                                        logLevelThreshold
                                                + " is not a valid log severity threshold. Valid severities are WARN/WARNING and ERROR.");
                        };
                recorder.setMaxLevelAllowed(level);
                slf4jLogger.info("Enabled to break the build on log level {}.", logLevelThreshold);
            } else {
                slf4jLogger.warn(
                        "Expected LoggerFactory to be of type '{}', but found '{}' instead. "
                                + "The --fail-on-severity flag will not take effect.",
                        LogLevelRecorder.class.getName(),
                        slf4jLoggerFactory.getClass().getName());
            }
        }

        // check for presence of deprecated options and print warning
        boolean fail = false;
        for (Option option : cliRequest.commandLine.getOptions()) {
            if (option.isDeprecated()) {

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Use one of the supported values: --fail-on-severity=error (strict, default behavior) or --fail-on-severity=warn / warning (also fails on warnings).
  2. Check .mvn/maven.config, wrapper scripts, and CI pipeline definitions for a stale --fos value and correct it.
  3. If you intended to fail on lower-severity messages, note it is unsupported by design; filter or grep the build log in your pipeline instead.
  4. If you saw only a warning instead of this error, replace the external SLF4J binding with the Maven default provider so the flag takes effect.

Example fix

# before
mvn --fail-on-severity=INFO

# after
mvn --fail-on-severity=WARN
Defensive patterns

Strategy: validation

Validate before calling

// Before building mvn args
String severity = "warn"; // from config
if (!Set.of("warn", "warning", "error").contains(severity.toLowerCase(Locale.ENGLISH))) {
    throw new IllegalArgumentException("--fail-on-severity must be WARN/WARNING/ERROR, got: " + severity);
}
List<String> args = List.of("--fail-on-severity=" + severity.toLowerCase(Locale.ENGLISH));

Try / catch

try {
    mavenCli.doMain(args, ...);
} catch (IllegalArgumentException e) {
    if (e.getMessage() != null && e.getMessage().endsWith("is not a valid log severity threshold. Valid severities are WARN/WARNING and ERROR.")) {
        // normalize config to WARN or ERROR and re-invoke once
    }
    throw e;
}

Prevention

When it happens

Trigger: mvn --fail-on-severity=INFO, --fos=DEBUG, --fos=TRACE, --fos=FATAL, or any non-empty value other than warn/warning/error, while the default Maven SLF4J provider is active. Values supplied through wrapper scripts or .mvn/maven.config (e.g. --fos info) hit the same path.

Common situations: Assuming the full log4j/slf4j level hierarchy (TRACE/DEBUG/INFO/WARN/ERROR/FATAL) is accepted. Copying configurations from Maven 3.9.x-era tooling or blog posts that used different severity names. Trying to fail on INFO-level messages, which this option deliberately does not support.

Related errors


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