简体   繁体   中英

How to add other Scala project as dependencies in IntelliJ (Scala Plugin)

I have IntelliJ Scala project A, and I need to create another Scala project B that depends on it. Creating a jar file from project A, and make the project B to depend on the jar file can one solution, or creating modules (not projects) can be another. However, I'd like to find a way to build the dependencies between projects if possible.

Is it possible to make project A depends on project B in IntelliJ (Scala Plugin) without resorting to jar files?

The solution you are looking for is SBT's multi-project build system. You can create the jar you need in one sub-project and make other sub-projects depend on it. IntelliJ's Scala mode is clever enough to understand sbt's multi-project builds. Simply import the resulting project as a new project in IntelliJ and you are good to go. I have a minimal example project demonstrating the concept. Clone it and play. The SBT documentation for multi-projects is here .

The sbt code below is the top level build.sbt file and should give you an idea of where to start. Note that each sub-project is contained in its own directory with its own src tree and root build.sbt (if needed).

scalaVersion in ThisBuild := "2.11.1"

scalacOptions in ThisBuild ++= Seq("-feature", "-language:postfixOps")

lazy val root = project in file(".") aggregate(lib,client,server)

lazy val lib = project in file("lib") settings(
  version := "1.0.0"
)

lazy val client = project in file("client") settings(
  version := "1.0.1",
  name := "mirv-client"
) dependsOn(lib)

lazy val server = project in file("server") settings(
  version := "1.0.2",
  name:="mirv-server"
) dependsOn(lib)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM