[2.x] Suppress multiple main classes warning when running tests (#9372)

In a project with multiple main classes, the "multiple main classes detected" warning is unwanted noise when running tests. This message is already suppressed for explicit run commands, now also suppress it for test.
This commit is contained in:
Merlin Hughes 2026-06-24 02:03:13 -04:00 committed by GitHub
parent 3a37da86f3
commit 7575c5a1be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 6 deletions

View File

@ -1140,19 +1140,20 @@ object Defaults extends BuildCommon with DefExtra {
selectMainClass := mainClass.value orElse askForMainClass(discoveredMainClasses.value),
run / mainClass := (run / selectMainClass).value,
mainClass := Def.uncached {
// Suppress warning for run commands (user is actively running, warning is noise)
def isRunCommand(s: String): Boolean = s match
// Suppress warning for run/test commands (user is actively running, warning is noise)
def isRunOrTestCommand(s: String): Boolean = s match
case "run" | "runMain" | "bgRun" | "bgRunMain" | "fgRun" | "fgRunMain" => true
case "test" | "testFull" | "testOnly" | "testQuick" | "testSelected" => true
case _ => false
val logWarning = state.value.currentCommand.forall(!_.commandLine.split(" ").exists {
case s if isRunCommand(s) => true
case r =>
case s if isRunOrTestCommand(s) => true
case r =>
// Handle both "/" (new syntax like Test/run) and ":" (old syntax like test:run)
r.split("[/:]") match {
case Array(parts*) =>
parts.lastOption match {
case Some(s) if isRunCommand(s) => true
case _ => false
case Some(s) if isRunOrTestCommand(s) => true
case _ => false
}
}
})