我试图将这个骗取-http库作为外部maven依赖项添加到我的新bazel项目中。但得到以下错误。我想我在没有完全理解它的情况下创建构建时做错了什么。努力学习。谢谢你的帮助。
error: object Service is not a member of package com.twitter.finagle
error: object util is not a member of package com.twitter
error: type Request is not a member of package com.twitter.finagle.http
error: object Response is not a member of package com.twitter.finagle.http
error: Symbol 'type com.twitter.finagle.Client' is missing from the classpath. This symbol is required by 'object com.twitter.finagle.Http'.
error: not found: value Await
相同的代码使用sbt工作。代码如下:
import com.twitter.finagle.{Http, Service}
import com.twitter.finagle.http
import com.twitter.util.{Await, Future}
object HelloWorld extends App {
val service = new Service[http.Request, http.Response] {
def apply(req: http.Request): Future[http.Response] =
Future.value(http.Response(req.version, http.Status.Ok))
}
val server = Http.serve(":8080", service)
Await.ready(server)
}
工作区文件
maven_install(
artifacts = [
"org.apache.spark:spark-core_2.11:2.4.4",
"org.apache.spark:spark-sql_2.11:2.4.1",
"org.apache.spark:spark-unsafe_2.11:2.4.1",
"org.apache.spark:spark-tags_2.11:2.4.1",
"org.apache.spark:spark-catalyst_2.11:2.4.1",
"com.twitter:finagle-http_2.12:21.8.0",
],
repositories = [
"https://repo.maven.apache.org/maven2/",
"https://repo1.maven.org/maven2/",
]
)
构建文件
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_binary")
package(default_visibility = ["//visibility:public"])
scala_binary(
name="helloworld",
main_class="microservices.HelloWorld",
srcs=[
"Main.scala",
],
deps = ["spark],
)
java_library(
name = "spark",
exports = [
"@maven//:com_twitter_finagle_http_2_12_21_8_0",
],
)
在我最初的SBT项目中工作的SBT依赖
libraryDependencies += "com.twitter" %% "finagle-http" % "21.8.0"
解决了问题,与在sbt中不同,在bazel中我单独添加了相关的依赖项。我将工作区修改如下:
maven_install(
artifacts = [
"com.twitter:finagle-http_2.12:21.8.0",
"com.twitter:util-core_2.12:21.8.0",
"com.twitter:finagle-core_2.12:21.8.0",
"com.twitter:finagle-base-http_2.12:21.8.0",
"com.fasterxml.jackson.module:jackson-module-scala_2.12:2.11.2",
"com.fasterxml.jackson.core:jackson-databind:2.11.2",
],
repositories = [
"https://repo.maven.apache.org/maven2/",
"https://repo1.maven.org/maven2/",
]
构建文件——
java_library(
name = "finagletrial",
exports = [
"@maven//:com_twitter_finagle_http_2_12_21_8_0",
"@maven//:com_twitter_util_core_2_12_21_8_0",
"@maven//:com_twitter_finagle_core_2_12_21_8_0",
"@maven//:com_twitter_finagle_base_http_2_12_21_8_0",
"@maven//:com_fasterxml_jackson_module_jackson_module_scala_2_12_2_11_2",
"@maven//:com_fasterxml_jackson_core_jackson_databind_2_11_2"
],