首页 > 解决方案 > 定义依赖项时如何为 linux 和 osx 加载 ReactiveMongo?

问题描述

我正在尝试为 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 进行开发)

标签: scalareactivemongo

解决方案


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

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"), 以在构建时使用环境变量定义目标操作系统。


推荐阅读