Vijay Patel
Vijay Patel

Reputation: 57

IntelliJ SBT multiproject builds and Dependencies reuse

I have a multiproject SBT build:

In the project folder at root level (root/project/Dependencies.scala), I have a Dependencies object containing dependency declarations:

object Dependencies {

  lazy val scalaLogging = "com.typesafe.scala-logging" %% "scala-logging" % "3.1.0"
  lazy val slf4j = "org.slf4j" % "slf4j-api" % "1.7.12"
}

In any of my subprojects (root/common/build.sbt), I have a build.sbt which tries to import Dependencies object:

import sbt._
import Dependencies._

libraryDependencies ++= Seq(
  nscalaTime,
  scalaLogging, slf4j, logback
)

This works fine from the command line build. However, from within IntelliJ I get red text as the IDE cannot resolve import Dependencies._

Is this a known IntelliJ issue for multi-project SBT builds?

To confirm, it does not break SBT compilation, just IntelliJ does not seem to be able to find the Dependencies object via the import and show red text everywhere.

Upvotes: 2

Views: 745

Answers (1)

20knots
20knots

Reputation: 547

I can confirm this has been an issue of IntelliJ IDEA with multi-project sbt builds. However this can be fixed in the current version "2017.1.2". Using the following lines in the main build.sbt file sets the dependencies of an application with two interdependent library projects:

// Projects in this build
lazy val `A_Lib` = project in file("A_Lib")
lazy val `B_Lib` = project in file("B_Lib") dependsOn(`A_Lib`)
lazy val `C_App` = project in file(".")

libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.12"

Each library project has its own build.sbt file. If for example If A_Lib or B_Lib depend on slf4j as well, it is sufficient to add

libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.12"

to the librarie's build.sbt file.

Upvotes: 1

Related Questions