Sbt / metals error: No build target for:

metals output error:

No build target for: /Users/john/projects/testgame/core/src/main.scala

root structure

├── build.sbt
├── core
│   └── src
│       └── main.scala

build.sbt

lazy val core = project.in(file("."))
   .settings(
      name := "core",
      scalaVersion := "3.6.2",
      scalacOptions ++= Seq(
         "-language:experimental.namedTuples"
      ),
   )

What is the issue?

1 Like

It should be core/src/main/main.scala according to the sbt standard layout (same as with maven)

3 Likes

Also I think you should have project.in(file("core")) or perhaps just project if you want the core subproject to be located in the core directory.

2 Likes

For future readers: what solved the error for me was specifying the entry point by

Compile / scalaSource := baseDirectory.value / "core" / "src",

or changing the base to core = project.in(file("core")) with the entry as

Compile / scalaSource := baseDirectory.value / "src",

Since I was wanting to avoid the verbose java-style folder structure and keep it simpler like other languages have.

1 Like

I think if the project is in(file(".")), it is the root project and default source position would be src/main/scala/main.scala. Unless the project included multiple modules, I see no need to place it in the additional directory.

As suggested by @Jasper-M, if the sources should be located in core directory, a natural thing would be to use just project or project.in(file("core")), which is the same thing if the project variable is called core, and then the default source position would then be core/src/main/scala/main.scala.

Overriding scalaSource is always possible, or you can manipulate unmanagedSourceDirectories , e.g. in my project I use this to add additional source folder:

  Compile / unmanagedSourceDirectories ++= Seq((ThisBuild / baseDirectory).value / "shared" / "src" / "main" / "scala"),
  Test / unmanagedSourceDirectories  ++= Seq((ThisBuild / baseDirectory).value / "shared" / "src" / "test" / "scala"),