Skip to content

Commit

Permalink
Update to JavaCPP 1.5.4 and use Detector.getPlatform to avoid "java.l…
Browse files Browse the repository at this point in the history
…ang.UnsatisfiedLinkError: no jnijavacpp in java.library.path" message.
  • Loading branch information
yukoba committed Dec 17, 2020
1 parent d482b71 commit cdefbba
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ of adding the proper native preset for your target platform as well. Remove ```-
```scala
// in build.sbt

javaCppPresetLibs ++= Seq("opencv" -> "4.3.0", "opencv-gpu" -> "4.3.0", "mkl-redist" -> "2020.1")
javaCppPresetLibs ++= Seq("opencv" -> "4.4.0", "opencv-gpu" -> "4.4.0", "mkl-redist" -> "2020.3")
fork := true

```
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ publishArtifact in Test := false

pomIncludeRepository := { _ => false }

libraryDependencies += "org.bytedeco" % "javacpp" % "1.5.3"
libraryDependencies += "org.bytedeco" % "javacpp" % "1.5.4"

scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature", "-Xlint", "-Xlog-free-terms")

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/org/bytedeco/sbt/javacpp/Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object Platform {
*/
val current: Seq[String] = sys.props.get(platformOverridePropertyKey) match {
case Some(platform) if platform.trim().nonEmpty => platform.split(' ')
case _ => Seq(Loader.getPlatform)
case _ => Seq(Loader.Detector.getPlatform)
}

}
}
24 changes: 20 additions & 4 deletions src/main/scala/org/bytedeco/sbt/javacpp/Plugin.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.bytedeco.sbt.javacpp

import scala.language.postfixOps
import sbt._
import sbt.Keys._

Expand All @@ -16,14 +15,18 @@ object Plugin extends AutoPlugin {
javaCppPlatform := Platform.current,
javaCppVersion := Versions.javaCppVersion,
javaCppPresetLibs := Seq.empty,
libraryDependencies += {
"org.bytedeco" % "javacpp" % javaCppVersion.value jar
libraryDependencies ++= "org.bytedeco" % "javacpp" % javaCppVersion.value +: {
if (isVersionGreaterThanEqual(javaCppVersion.value, 1, 5, 3)) {
javaCppPlatform.value.map { platform =>
"org.bytedeco" % "javacpp" % javaCppVersion.value classifier platform
}
} else Seq.empty
},
javaCppPresetDependencies)
}

object Versions {
val javaCppVersion = "1.5.3"
val javaCppVersion = "1.5.4"
}

object autoImport {
Expand Down Expand Up @@ -75,6 +78,19 @@ object Plugin extends AutoPlugin {
case _ => (version, "org.bytedeco")
}

private def isVersionGreaterThanEqual(version: String, major: Int, minor: Int, patch: Int): Boolean = {
if (version.endsWith("-SNAPSHOT")) {
true
} else {
version match {
case VersionSplit(a :: b :: c :: _) =>
(a == major && b == minor && c >= patch) || (a == major && b > minor) || a > major
case VersionSplit(a :: b :: _) =>
(a == major && b == minor && 0 == patch) || (a == major && b > minor) || a > major
}
}
}

private object VersionSplit {
def unapply(arg: String): Option[List[Int]] =
Try(arg.split('.').map(_.toInt).toList).toOption
Expand Down
3 changes: 2 additions & 1 deletion src/sbt-test/sbt-javacpp/simple/build.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

version := "0.1"

scalaVersion := "2.12.11"

libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"

javaCppPresetLibs ++= Seq("mkl" -> "2020.1", "mkl-redist" -> "2020.1")
javaCppPresetLibs ++= Seq("mkl" -> "2020.3", "mkl-redist" -> "2020.3")

fork := true

0 comments on commit cdefbba

Please sign in to comment.