scala 在定义依赖关系时,如何加载Linux和OSX的Reactive Mongo?

4smxwvx5  于 2022-11-09  发布在  Scala
关注(0)|答案(1)|浏览(170)

我正在尝试为Linux和OSX平台设置我的RractiveMongo依赖项。
我试过这个:

val mongoShadedNativeLinux = "org.reactivemongo"          % "reactivemongo-shaded-native"   % s"$reactivemongoVersion-linux-x86-64" classifier "linux-x86_64"
  val mongoShadedNative      = "org.reactivemongo"          % "reactivemongo-shaded-native"   % s"$reactivemongoVersion-osx-x86-64" classifier "natives-osx"

但我得到了一个错误:
https://repo1.maven.org/maven2/org/reactivemongo/reactivemongo-shaded-native/0.20.3-osx-x86-64/reactivemongo-shaded-native-0.20.3-osx-x86-64-natives-osx.jar:未找到:https://repo1.maven.org/maven2/org/reactivemongo/reactivemongo-shaded-native/0.20.3-osx-x86-64/reactivemongo-shaded-native-0.20.3-osx-x86-64-natives-osx.jar
如何加载正确的库?我是否必须在Linux服务器上构建项目才能将其用于生产(使用Linux进行生产,使用OSX进行开发)

umuewwlo

umuewwlo1#

正如您在演示应用程序的构建中所看到的,您可以根据操作系统定制依赖项。

libraryDependencies += {
  val os = sys.props.get("os.name") match {
    case Some(osx) if osx.toLowerCase.startsWith("mac") =>
      "osx"

    case _ =>
      "linux"
  }

  val (playVer, nativeVer) = reactiveMongoVer.split("-").toList match {
    case major :: Nil =>
      s"${major}-play27" -> s"${major}-${os}-x86-64"

    case vs @ _ => {
      val pv = ((vs.init :+ "play27") ++ vs.lastOption.toList)
      val nv = ((vs.init :+ os :+ "x86-64") ++ vs.lastOption.toList)

      pv.mkString("-") -> nv.mkString("-")
    }
  }

  "org.reactivemongo" % "reactivemongo-shaded-native" % nativeVer
}

您可以将sys.props.get("os.name")替换为sys.env.get("FOO"),以便在构建时使用环境变量定义目标操作系统。

相关问题