sbt: How do I resolve Maven dependencies that uses

2020-06-21 13:11发布

问题:

For example:

lazy val someProject = project
  .settings(
    scalaVersion := "2.12.3",
    libraryDependencies += "org.jcuda" % "jcuda" % "0.8.0"
  )

The above does not resolve:

sbt:someProject> update
[info] Updating ...
[info] downloading https://repo1.maven.org/maven2/org/jcuda/jcuda/0.8.0/jcuda-0.8.0.jar ...
[warn]  Detected merged artifact: [NOT FOUND  ] org.jcuda#jcuda-natives;0.8.0!jcuda-natives.jar (16ms).
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/jcuda/jcuda-natives/0.8.0/jcuda-natives-0.8.0-${jcuda.os}-${jcuda.arch}.jar
[info]  [SUCCESSFUL ] org.jcuda#jcuda;0.8.0!jcuda.jar (227ms)
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::              FAILED DOWNLOADS            ::
[warn]  :: ^ see resolution messages for details  ^ ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.jcuda#jcuda-natives;0.8.0!jcuda-natives.jar
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::

Note the ${jcuda.os} appearing in the error message.

回答1:

As a workaround you can set up a custom setting and provide the value for the Maven property as a JVM property:

lazy val mavenProps = settingKey[Unit]("workaround for Maven properties")
lazy val jcudaOs = settingKey[String]("")
lazy val jcudaArch = settingKey[String]("")
lazy val someProject = project
  .settings(
    scalaVersion := "2.12.3",
    libraryDependencies += "org.jcuda" % "jcuda" % "0.8.0",
    jcudaOs := "linux",
    jcudaArch := "x86_64",
    mavenProps := {
      sys.props("jcuda.os") = jcudaOs.value
      sys.props("jcuda.arch") = jcudaArch.value
      ()
    }
  )

This splits out the missing Maven properties as sbt setting, and then translates them into sys.props at the load time of the build.



标签: scala maven sbt