scala - 定义依赖项时如何为 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 进行开发)
解决方案
正如您在演示应用程序的构建中看到的那样,您可以根据操作系统自定义依赖项。
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")
, 以在构建时使用环境变量定义目标操作系统。
推荐阅读
- css - *[data-some-id='XX'] 和 [data-some-id='XX'] 在性能方面有区别吗?
- python - 尝试比较两个 UTF-8 编码的文本文件以查找和计算相似的单词
- excel - 有没有办法同步两个工作簿?
- angularjs - ASP.Net Web Api & Angularjs:多个文件上传
- c# - 如何使用单个 ajax 调用填充多个下拉列表
- openssl - 证书中的“-----BEGIN TRUSTED CERTIFICATE-----”是什么意思?
- python - 为什么我调用函数后全局变量没有更新?
- python - 如何将这段数据写入 csv 文件?
- python - 如何用python打开可执行文件
- php - 如何为多个按钮分配ajax变量