如果我定义一个依赖于两个外部源文件夹的sbt scala项目,则分析将无法正常进行。所以说我定义以下build.sbt:
lazy val root = project.in(file("."))
.settings(
name := "repro",
version := "1.0",
scalaVersion := "2.11.8",
unmanagedSourceDirectories in Compile +=
baseDirectory.value / ".." / "ext1" / "src" / "main" / "scala",
unmanagedSourceDirectories in Compile +=
baseDirectory.value / ".." / "ext2" / "src" / "main" / "scala"
)
使得ext1中的源依赖于ext2中的源。因此,在此示例中,我在ext1中定义了trati T1,在ext2中定义了取决于T1的特征T2。我的项目中有一个依赖于T2的课程。这将在sbt中全部编译正常。但是,当我在IntelliJ中导入此sbt项目时,它将进行编译。但是,当我在编辑器中打开特征T2时,当我引用T1时出现错误,提示“无法解析ext1”。为什么会出现此错误?
可以通过以下链接在github上找到此问题的再现:
https://github.com/hughgearse/repro
答案 0 :(得分:0)
在ext1/build.sbt
中创建构建定义
lazy val root = project.in(file("."))
.settings(
name := "ext1",
version := "1.0",
scalaVersion := "2.11.8"
)
,然后通过RootProject
引用ext1
作为ext2/build.sbt
中的外部版本
val ext1 = RootProject( file("../ext1") )
lazy val root = project.in(file(".")).dependsOn(ext1)
.settings(
name := "ext2",
version := "1.0",
scalaVersion := "2.11.8"
)
然后类似地将两者都引用为repro/build.sbt
中的外部版本
val ext1 = RootProject( file("../ext1") )
val ext2 = RootProject( file("../ext2") )
lazy val root = project.in(file(".")).dependsOn(ext1, ext2)
.settings(
name := "repro",
version := "1.0",
scalaVersion := "2.11.8",
unmanagedSourceDirectories in Compile +=
baseDirectory.value / ".." / "ext1" / "src" / "main" / "scala",
unmanagedSourceDirectories in Compile +=
baseDirectory.value / ".." / "ext2" / "src" / "main" / "scala"
)
重新导入repro
项目和IntelliJ应该能够分析所有源。