当前位置: 首页 > 知识库问答 >
问题:

如何在build.sbt中添加依赖项目以运行sbt编译

柳翼
2023-03-14

更新

organization := "com.org"

name := "projB"

version := "1"

resolvers ++= Seq(
  "Typesafe" at "http://repo.typesafe.com/typesafe/releases/",
  "Java.net Maven2 Repository" at "http://download.java.net/maven/2/",
 )

lazy val projB = project.dependsOn(projA)

// the library dependencies of springframework here
organization := "com.org"

name := "proj A"

version := "1"

resolvers ++= Seq(
  "Typesafe" at "http://repo.typesafe.com/typesafe/releases/",
 "Java.net Maven2 Repository" at "http://download.java.net/maven/2/",
 )

// the library dependencies of springframework here

当我在proj B上进行sbt编译时,它抛出错误,依赖类找不到。类Hbase在Proj A中。

[error] import com.org.config.Hbase;
[error] **\hbase\HbaseDAO.java:38:1:
cannot find symbol
[error]   symbol:   class Hbase
[error]   location: class com.org.hbase.HbaseDAO
[error]         private Hbase hbase;
[error] (Compile / compileIncremental) javac returned non-zero exit code
[error] Total time: 6 s, completed 29/08/2019 9:58:39 AM

在建议之后更新了build.sbt:

inThisBuild(
 Seq(
   organization := "com.org",
   version := "1",
   resolvers ++= Seq(
   "Typesafe" at "http://repo.typesafe.com/typesafe/releases/",
   "Java.net Maven2 Repository" at "http://download.java.net/maven/2/",
  )
 )
)

lazy val root = project
  .in(file("."))
  .aggregate(projA,projB)

lazy val projA = project.settings(
    // project A settings and library dependencies

libraryDependencies += "org.springframework.boot" % "spring-boot-starter- 
parent" % "2.1.6.RELEASE" pomOnly()

libraryDependencies += "org.springframework.boot" % "spring-boot-starter- 
web" % "2.1.6.RELEASE"

libraryDependencies += "org.springframework.data" % "spring-data-hadoop- 
hbase" % "2.3.0.RELEASE"

libraryDependencies += "org.mortbay.jetty" % "jetty" % "7.0.0.pre5"

libraryDependencies += "io.netty" % "netty-all" % "5.0.0.Alpha2"

libraryDependencies += "commons-beanutils" % "commons-beanutils" % "1.9.4"

libraryDependencies += "commons-beanutils" % "commons-beanutils-core" % 
"1.8.3"

libraryDependencies += "xerces" % "xercesImpl" % "2.12.0"

libraryDependencies += "org.apache.hadoop" % "hadoop-yarn-server- 
nodemanager" % "3.2.0"

libraryDependencies += "org.apache.hadoop" % "hadoop-common" % "3.2.0"

libraryDependencies += "org.apache.hadoop" % "hadoop-common" % "2.7.0"

libraryDependencies += "org.apache.hadoop" % "hadoop-client" % "3.2.0"

libraryDependencies += "org.apache.hbase" % "hbase-client" % "2.1.1"

libraryDependencies += "org.apache.hbase" % "hbase" % "2.1.1" pomOnly()

libraryDependencies += "org.apache.hbase" % "hbase-common" % "2.1.1"
)

lazy val projB = project
 .dependsOn(projA)
  .settings(
   // project B settings and library dependencies
libraryDependencies += "org.springframework.boot" % "spring-boot-starter- 
parent" % "2.1.6.RELEASE" pomOnly()

libraryDependencies += "org.springframework.boot" % "spring-boot-starter- 
web" % "2.1.6.RELEASE"

libraryDependencies += "org.springframework.data" % "spring-data-hadoop- 
hbase" % "2.3.0.RELEASE"

libraryDependencies += "org.mortbay.jetty" % "jetty" % "7.0.0.pre5"

libraryDependencies += "io.netty" % "netty-all" % "5.0.0.Alpha2"

libraryDependencies += "commons-beanutils" % "commons-beanutils" % "1.9.4"

libraryDependencies += "commons-beanutils" % "commons-beanutils-core" % 
"1.8.3"

libraryDependencies += "xerces" % "xercesImpl" % "2.12.0"

libraryDependencies += "org.apache.hadoop" % "hadoop-yarn-server- 
nodemanager" % "3.2.0"

libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % 
"2.10.0.pr2"

libraryDependencies += "org.apache.hadoop" % "hadoop-common" % "3.2.0"

libraryDependencies += "org.apache.hadoop" % "hadoop-client" % "3.2.0"

libraryDependencies += "org.apache.hbase" % "hbase-client" % "2.1.1"

libraryDependencies += "org.apache.hbase" % "hbase" % "2.1.1" pomOnly()

libraryDependencies += "org.apache.hbase" % "hbase-common" % "2.1.1"

)
libraryDependencies += "org.springframework.boot" % "spring-boot-starter- 
web" % "2.1.6.RELEASE"

“;”应为,但在projB设置中为该行抛出了找到的字符串文本。

我对这个错误一无所知。

共有1个答案

骆利
2023-03-14

查看您发布的两个片段,我猜您有两个单独的build.sbt文件,每个子项目一个。这使得它们独立,一个项目只是看不到另一个项目。虽然可以为子项目提供多个build.sbt文件,但建议在项目根目录中的单个build.sbt文件中定义整个multiproject构建。

例如,如果您的项目结构如下:

├── project
│  ├── build.properties
│  └── plugins.sbt
├── projA
│  └── src
├── projB
│  └── src
└── build.sbt

然后可以将所有构建设置和子项目关系放在根build.sbt:

inThisBuild(
  Seq(
    organization := "com.org",
    version := "1",
    resolvers ++= Seq(
      "Typesafe" at "http://repo.typesafe.com/typesafe/releases/",
      "Java.net Maven2 Repository" at "http://download.java.net/maven/2/",
    )
  )
)

lazy val root = project
  .in(file("."))
  .aggregate(projA, projB)

lazy val projA = project
  .settings(
    // project A settings and library dependencies
  )

lazy val projB = project
  .dependsOn(projA)
  .settings(
    // project B settings and library dependencies
  )
 类似资料:
  • 我有一个sbt-plugin,当启用时,通过scalac选项添加scalac编译器插件。一切都很好。 null

  • 您好,我正在尝试在构建中下载,,,以及。sbt文件如下: 我只是把这个联机,所以我不确定使用哪个版本等。 有人能向我解释一下我应该如何修复这个. sbt文件吗?我花了几个小时试图弄清楚,但没有一个建议奏效。我安装了通过家酿和我的版本 我所有的错误都是关于:

  • 我有一个sbt插件项目,使用多项目构建。我想使用这个插件作为其他sbt项目的依赖项。我已经创建了一个插件,但是当我把这个插件添加到project中时,我似乎不能正确地连接依赖项。 我在这里漏掉了什么?

  • 我使用的是Android studio版本 在项目级分级中: 模块级别等级: 当我导入它时,它发生错误 导入此时 xml错误 错误图片 在xml中添加此标记时发生错误 为此给出解决方案!!!

  • 我想要添加此依赖项编译到我的Android studio项目中。 当将此添加到依赖项中并单击同步时,显示此错误:

  • 我正在试图弄清楚如何为我自己的基于Scalding的项目创建文件。 滚烫源结构没有文件。相反,它具有构建定义。 将我自己的sbt项目与Scalding集成的正确方法是什么,这样我也可以稍后在Eclipse中用插件导入它? 我得到错误: 更新2 在执行和之后,我仍然有相同的编译错误。 'sbt Eclipse'创建未在Eclipse下编译的Eclipse项目,并报告以下错误: