Scala/Mill: Step 4, Specifying a Main Class in

As another example of the Scala Mill build tool, when you have multiple main methods in a Scala/Mill project you’ll need to specify which main method you want to run in your configuration file. If you don’t, you’ll see an error message like this:

1 targets failed
HelloWorld.finalMainClass Multiple main classes found (hello.Hello,hello.Hello2)
please explicitly specify which one to use by overriding mainClass

This is the syntax for overriding mainClass:

def mainClass = Some("hello.Hello")

This says that you want to run the main method that’s in the Hello class that’s in the hello package.

A complete Scala Mill file example

Here’s a complete Mill example for a small Scala project I’ve been working on. The last line of this file demonstrates the use of mainClass:

object RssAtomReader extends ScalaModule {

    def scalaVersion = "2.12.11"

    object test extends Tests {
        // dependencies for testing
        def ivyDeps = Agg(
        def testFrameworks = Seq("")

    // `::` for scala deps, `:` for java deps
    def ivyDeps = Agg(

    // pass a -D command-line arg to my application
    def forkArgs = Seq("-Dconfig.file=RssAtomReader/src/main/resources/application.conf")

    // with mill you need to specify the main class when you have more than one
    def mainClass = Some("hello.Hello")


In my project I have multiple main methods, and the last line of this file shows how I define which Scala (or Java) class has the main method that I want to run when I issue this command:

mill RssAtomReader

In a slightly related note, this is a JavaFX project, and in the forkArgs line I show how to pass a JVM argument to my application when I run it.

books by alvin