Multi project setup - No main class detected

Viewed 287

I have the following simple project setup

lazy val root = project.in(file(".")).aggregate(kalosrpc, kalosmodel)

lazy val kalosrpc = project.in(file("kalosrpc")).dependsOn(kalosmodel)

lazy val kalosmodel = project
  .settings(
    libraryDependencies ++= Seq(
      dependencies.slf4j,
      dependencies.slick,
      dependencies.mysql
    )
  )

lazy val kalosgen = project
  .settings(
    libraryDependencies ++= Seq(
      dependencies.slf4j,
      dependencies.slick,
      dependencies.slickCodeGen
    )
  )

With the following directory structure

|__ api 
   |__ kalosgen
      |__ src
         |__ scala
            |__ Main.scala
   |__ kalosmodel
      |__ src
         |__ scala
            |__ Main.scala
   |__ kalosrpc
      |__ src
         |__ scala
            |__ Main.scala

I'm trying to run only the code in kalosgen, but when I open the sbt console and do

project kalosgen
run

I see

[error] java.lang.RuntimeException: No main class detected.
[error]     at scala.sys.package$.error(package.scala:26)
[error] (Compile / bgRun) No main class detected.

Here is the contents of kalosgen/src/scala/Main.scala

import slick.codegen.SourceCodeGenerator

object Main extends App {
  val url = "hidden"
  val user = "hidden"
  val password = "hidden"
  val dbDriver = "com.mysql.jdbc.Driver"
  val profile = "slick.jdbc.MySQLProfile"
  SourceCodeGenerator.main(
    Array(
      profile,
      dbDriver,
      url,
      ".",
      "kalosmodel",
      user,
      password
    )
  )
}

As far as I can tell this setup is correct but it won't run and googling the error message has been no help. I've tried using class instead of object and specifying the main class in the build.sbt but nothing is working.

1 Answers

main subdirectory might be missing from the path. Try changing the structure to

kalosgen/src/main/scala/Main.scala

instead of

kalosgen/src/scala/Main.scala
Related