Skip to content
Latchkey

sbt "No main class detected" on run

sbt looked for a class with a main method (or an object extending App) to run and found none, or found several and could not choose.

What this error means

sbt run, stage, or assembly fails with No main class detected or asks you to pick among multiple. It is deterministic, driven by what sbt discovers on the classpath.

sbt
[error] (Compile / run) No main class detected.
[error] Total time: 2 s

Common causes

No discoverable entry point

The project has no object Main extends App and no method def main(args: Array[String]): Unit, so sbt has nothing to run.

Entry point not on the run classpath

The main lives in Test sources or a module that the run configuration does not include.

Multiple mains without a chosen one

Several mains exist and mainClass is unset, so sbt cannot pick automatically in CI.

How to fix it

Set the main class explicitly

Tell sbt which class to run so CI is deterministic.

build.sbt
Compile / mainClass := Some("com.example.Main")

Provide a valid entry point

Main.scala
object Main {
  def main(args: Array[String]): Unit = println("ok")
}

Run a specific main from the CLI

Disambiguate at invocation time.

CI step
sbt "runMain com.example.Main"

How to prevent it

  • Pin mainClass in build.sbt for reproducible runs.
  • Keep entry points in main sources, not test.
  • Document the entry point for multi-module builds.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →