多项目设置-未检测到主类

时间:2019-06-28 14:55:42

标签: scala sbt

我有以下简单的项目设置

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
    )
  )

具有以下目录结构

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

我试图只运行kalosgen中的代码,但是当我打开sbt控制台并执行

project kalosgen
run

我知道

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

这是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
    )
  )
}

据我所知,此设置正确无误,但无法运行,并且搜索错误消息没有帮助。我尝试使用class代替object,并在build.sbt中指定主类,但没有任何效果。

1 个答案:

答案 0 :(得分:4)

路径中可能缺少

main子目录。尝试将结构更改为

kalosgen/src/main/scala/Main.scala

代替

kalosgen/src/scala/Main.scala