scalareactivemongo

How to load the ReactiveMongo for both linux and osx when defining the dependencies?


I am trying to setup my RractiveMongo dependancy for both linux and osx platforms.

I tried this:

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"

But I get an error:

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: not found: 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

How do I load the correct library? And do I have to build the project on a linux server to build it for production (using linux for prod, osx for development)


Solution

  • As you can see in the build of the demo application, you can customize the dependency according OS.

    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
    }
    

    You can replace sys.props.get("os.name") by sys.env.get("FOO"), to define the target OS using a environment variable at build-time.