2

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)

cchantep
  • 9,118
  • 3
  • 30
  • 41
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
  • Scala is compiled like a Java to the byte code. Byte code runs on JVM and libraries doesn't think about platform witch will be used on runtime. So this is the reason that scala libraries don't have versions for different OSs. Why you are trying specify libs for different OSs? – Boris Azanov May 17 '20 at 18:25
  • @BorisAzanov because I am developing on osx, and production is linux... – Blankman May 17 '20 at 18:31
  • you can see there are different versions for osx and linux: https://mvnrepository.com/artifact/org.reactivemongo/reactivemongo-shaded-native – Blankman May 17 '20 at 18:32
  • Why would you load both? You need to indicate the dependency according the target env, which is either OSX or Linux, but not both. – cchantep May 19 '20 at 11:59

1 Answers1

3

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.

cchantep
  • 9,118
  • 3
  • 30
  • 41