How to manage multiple interdependent modules with SBT and IntelliJ IDEA?

前端 未结 2 1637
渐次进展
渐次进展 2021-01-30 06:37

I\'m developing several modules with dependencies among them, and would like to work with them all together in one IDEA project. I\'m using sbt-idea to generate IDEA projects f

2条回答
  •  忘了有多久
    2021-01-30 06:38

    It seems to be an sbt restriction that the subprojects must live in subdirectories of the master project (i.e., file("../foo") is not allowed). This is not really what I want (what if a module--such as a "utils" or "commons" package--is used in two different master projects?) but I can live with it.

    With sbt 13.5 and intellij 13.x, you can specify inter-project dependency with relative path, using a Build.scala. Let's say you have two projects, a core project commons and another project foo, both living in a common directory code/

    1. create Build.scala under code/foo/project/
    2. put this code snippet insde Build.scala

      object ProjectDependencies {
          val commons = RootProject(file("../commons"))
      }
      
      object ProjectBuild extends Build {
          import ProjectDependencies._
      
          lazy val root = Project(id = "foo", base = file(".")).dependsOn(commons)
      }
      
    3. Generate your IntelliJ project via sbt by sbt gen-idea

提交回复
热议问题