gpt4 book ai didi

scala - SBT 多项目设置,其中子项目构建文件依赖于非托管 JAR

转载 作者:行者123 更新时间:2023-12-04 12:38:54 24 4
gpt4 key购买 nike

设想:

  • 我想开发一个用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 的非托管库在 sbt compile 时找不到在 projectA 范围内运行 - 即使使用 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),但它们似乎都没有面临build设置(不仅是代码!)也依赖于这些非托管库的问题。
  • How to inherit unmanaged dependencies in submodules in sbt?
  • How to have sbt multi-project builds configure setting for subprojects? )
  • 最佳答案

    好的 build.sbt 中的这些更改它适用于我的机器:

    //unmanagedBase := baseDirectory.value / ".." / "projectB" / "deploy" / "lib"
    // this only defines the unmanagedBase of Project A


    //lazy val projectB = RootProject(file("../projectB/src/project"))
    // see the project setup below
    lazy val projectB = RootProject(file("../projectB"))
    lazy val projectBmmt = RootProject(file("../projectB/mmt"))

    lazy val projectA = Project(id = "projectA", base = file(".")).settings(
    name := "projectA",
    version := "0.1",
    scalaVersion := "2.12.8",
    scalacOptions in ThisBuild ++= Seq("-unchecked", "-deprecation"),
    // unmanagedBase in ThisBuild := baseDirectory.value / ".." / "projectB" / "deploy" / "lib"
    // this only defines the unmanagedBase of Project A
    ).dependsOn(projectB, projectBmmt)

    这是我的文件设置:
    enter image description here

    关于scala - SBT 多项目设置,其中子项目构建文件依赖于非托管 JAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54980499/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com