score:2

Accepted answer

You need to use a multi-project SBT build file. That is, have one build.sbt file for the entire project. IntelliJ should honor that without a problem.

I think your build.sbt file, which should go in your project's root directory, would need to look like this:

lazy val commonSettings = Seq(
  scalaVersion := "2.12.1",
  version := "0.1"
)

lazy val common = project.in(file("sbt_testing/common")).
settings(commonSettings: _*).
settings(
  name := "common"
)

lazy val hello = project.in(file("sbt_testing/hello")).
dependsOn(common).
settings(commonSettings: _*).
settings(
  name := "Hello"
)

As you can see, you can group settings common to both projects and also ensure better consistency between them.

You will need to remove the build.sbt files in sbt_testing/common and sbt_testing/hello.

UPDATE: Corrected use of commonSettings in the SBT build.sbt file. Apologies for the confusion!

UPDATE 2: In order to run the code in the HelloWorld class, you will need to do the following (I also renamed the "root" project to "hello"):

$ sbt
[info] Loading global plugins from /home/user/.sbt/0.13/plugins
[info] Loading project definition from /home/user/src/multiSbt/project
[info] Set current project to multisbt (in build file:/home/user/src/multiSbt/)
> project hello
[info] Set current project to Hello (in build file:/home/user/src/multiSbt/)
> run
[info] Compiling 1 Scala source to 
/home/user/src/multiSbt/sbt_testing/hello/target/scala-2.12/classes...
[info] Running HelloWorld 
Hello, world!
This is from common: testing 123
[success] Total time: 3 s, completed May 1, 2017 3:27:16 PM

For more information on SBT multi-project builds, refer to the official documentation...


Related Query

More Query from same tag