【发布时间】:2019-07-25 14:29:13
【问题描述】:
场景:
- 我想开发一个用 Scala 编写的 projectA,它依赖于 projectB,也是用 Scala 编写的。
- 我经常需要修改projectB。因此,我将拥有 projectB 的本地 Git 克隆(如 my repository 中的子模块)。
- 现在 projectA 应该直接从 projectB 的克隆 Git 存储库中提取对 projectB 的依赖项。
我现在有以下设置,也可以在 GitHub 上找到:https://github.com/ComFreek/sbt-multi-project-question
| - .git
|
| - projectA
| | - src
| | - build.sbt
|
| - projectB (Git submodule)
| | - src
| | | - build.sbt
| | | - project
| | | - project.sbt
| | | - ...
在projectA/build.sbt 试过:
unmanagedBase := baseDirectory.value / ".." / "projectB" / "deploy" / "lib"
lazy val projectB = RootProject(file("../projectB/src/project"))
lazy val projectA = Project(id = "projectA", base = file(".")).settings(
name := "projectA",
version := "0.1",
scalaVersion := "2.12.8",
scalacOptions in ThisBuild ++= Seq("-unchecked", "-deprecation")
).dependsOn(projectB)
但是,projectB/src/build.sbt 似乎使用放入 projectB/deploy/lib 的非托管库,当在 projectA 范围内运行 sbt compile 时找不到这些库 - 即使设置了 unmanagedBase 属性。
具体可以如下复现:
- 在
projectA中打开一个 SBT shell - 运行
compile并获取[IJ]sbt:projectA> compile [info] Compiling 13 Scala sources to ...\sbt-multi-project-question\projectB\src\project\target\scala-2.12\classes ... [error] ...\sbt-multi-project-question\projectB\src\project\File.scala:19:11: object tools is not a member of package scala [error] scala.tools.nsc.io.File(f.toString).appendAll(strings:_*) [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\Utils.scala:31:14: object Keys is not a member of package sbt [error] import sbt.Keys.packageBin [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\Utils.scala:33:36: not found: value Def [error] def deployPackage(name: String): Def.Initialize[Task[Unit]] = [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\Utils.scala:34:5: not found: value packageBin [error] packageBin in Compile map {jar => deployTo(Utils.deploy / name)(jar)} [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\Utils.scala:34:19: not found: value Compile [error] packageBin in Compile map {jar => deployTo(Utils.deploy / name)(jar)} [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\Utils.scala:45:39: type File is not a member of package sbt [error] def deployTo(target: File)(jar: sbt.File): Unit = { [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\Utils.scala:39:36: not found: value Def [error] def deployMathHub(target: File): Def.Initialize[Task[Unit]] = [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\Utils.scala:40:5: not found: value packageBin [error] packageBin in Compile map {jar => deployTo(target)(jar)} [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\Utils.scala:40:19: not found: value Compile [error] packageBin in Compile map {jar => deployTo(target)(jar)} [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\Utils.scala:123:25: not found: type Logger [error] def delRecursive(log: Logger, path: File): Unit = { [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:8:44: not found: type Project [error] case class VersionSpecificProject(project: Project, excludes: Exclusions) { [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:13:48: not found: type Project [error] def aggregate(projects: ProjectReference*) : Project = project.aggregate(excludes(projects.toList) :_*) [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:13:27: not found: type ProjectReference [error] def aggregate(projects: ProjectReference*) : Project = project.aggregate(excludes(projects.toList) :_*) [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:17:48: not found: type Project [error] def dependsOn(projects: ProjectReference*) : Project = { [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:17:27: not found: type ProjectReference [error] def dependsOn(projects: ProjectReference*) : Project = { [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:18:47: not found: type ClasspathDep [error] def toClassPathDep(p: ProjectReference) : ClasspathDep[ProjectReference] = p [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:18:27: not found: type ProjectReference [error] def toClassPathDep(p: ProjectReference) : ClasspathDep[ProjectReference] = p [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:23:59: not found: type Project [error] def aggregatesAndDepends(projects: ProjectReference*) : Project = { [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:23:38: not found: type ProjectReference [error] def aggregatesAndDepends(projects: ProjectReference*) : Project = { [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:24:47: not found: type ClasspathDep [error] def toClassPathDep(p: ProjectReference) : ClasspathDep[ProjectReference] = p [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:24:27: not found: type ProjectReference [error] def toClassPathDep(p: ProjectReference) : ClasspathDep[ProjectReference] = p [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:30:37: not found: type Project [error] implicit def fromProject(project: Project) : VersionSpecificProject = VersionSpecificProject(project, Exclusions()) [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:34:28: not found: type ProjectReference [error] case class Exclusions(lst: ProjectReference*) { [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:31:61: not found: type Project [error] implicit def toProject(vProject: VersionSpecificProject): Project = vProject.project [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:35:68: not found: type ProjectReference [error] private def javaVersion(versions: List[String], exclusions: List[ProjectReference]) : Exclusions = { [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:43:22: not found: type ProjectReference [error] def :::(lst2: List[ProjectReference]) = Exclusions(lst.toList ::: lst2 : _*) [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:39:25: not found: type ProjectReference [error] def java7(exclusions: ProjectReference*): Exclusions = javaVersion(List("1.7", "7"), exclusions.toList) [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:40:25: not found: type ProjectReference [error] def java8(exclusions: ProjectReference*): Exclusions = javaVersion(List("1.8", "8"), exclusions.toList) [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:41:25: not found: type ProjectReference [error] def java9(exclusions: ProjectReference*): Exclusions = javaVersion(List("1.9", "9"), exclusions.toList) [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:46:18: not found: value ScopeFilter [error] def toFilter : ScopeFilter.ProjectFilter = { [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:47:5: not found: value inAnyProject [error] inAnyProject -- inProjects(lst :_*) [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:47:21: not found: value inProjects [error] inAnyProject -- inProjects(lst :_*) [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:51:28: not found: type ProjectReference [error] private def equals(left: ProjectReference, right: ProjectReference) : Boolean = { [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:51:53: not found: type ProjectReference [error] private def equals(left: ProjectReference, right: ProjectReference) : Boolean = { [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:61:25: not found: type ProjectReference [error] def excludes(project: ProjectReference) : Boolean = lst.exists(equals(_, project)) [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:62:54: not found: type ProjectReference [error] def apply(projects: List[ProjectReference]) : List[ProjectReference] = projects.filterNot(this.excludes) [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:62:28: not found: type ProjectReference [error] def apply(projects: List[ProjectReference]) : List[ProjectReference] = projects.filterNot(this.excludes) [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:64:17: not found: type ProjectReference [error] def map[B](f: ProjectReference => B) : Seq[B] = lst.map(f) [error] ^ [error] ...\sbt-multi-project-question\projectB\src\project\VersionSpecificProject.scala:65:21: not found: type ProjectReference [error] def foreach[U](f: ProjectReference => U) : Exclusions = {lst.foreach[U](f); this } [error] ^ [error] 39 errors found [error] (ProjectRef(uri("file:/.../sbt-multi-project-question/projectB/src/project/"), "project") / Compile / compileIncremental) Compilation failed [error] Total time: 5 s, completed 04.03.2019, 10:10:34 [IJ]sbt:projectA>
但是,以下工作:
- 在
projectB/src中打开一个SBT shell。 - 运行
compile
请注意,在我的机器上大约需要 12 分钟并输出大量警告,但没有错误。
研究。有一些资源解释了如何在子项目之间共享非托管库(例如下面的 1 和 2),但它们似乎都没有面临 构建设置(不仅是代码!)还依赖于那些非托管库。
【问题讨论】:
-
如果您没有任何非托管依赖项,您的设置是否有效?
-
@pme 我不确定,我想在不过多修改依赖项目的构建设置的情况下,需要做很多工作才能拉出那些非托管依赖项。
-
你在这个项目@ComFreek 上找到解决方案了吗?
-
@Rex 还没有,目前,我正在测试pme's 的建议,请参阅那里的 cmets。
-
啊,我明白了。但我认为他们建议的一切都是很好的答案。这是这里最重要的关键字
.aggregate()和.dependsOn()
标签: scala sbt build-system