sbt:如何解决使用Maven属性的Maven依赖项
问题描述:
例如:
lazy val someProject = project
.settings(
scalaVersion := "2.12.3",
libraryDependencies += "org.jcuda" % "jcuda" % "0.8.0"
)
以上内容无法解决:
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] ::::::::::::::::::::::::::::::::::::::::::::::
请注意错误消息中出现的${jcuda.os}
.
Note the ${jcuda.os}
appearing in the error message.
答
作为解决方法,您可以设置自定义设置,并将Maven属性的值提供为JVM属性:
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
()
}
)
这会将缺少的Maven属性拆分为sbt设置,然后在构建的加载时将其转换为sys.props
.
This splits out the missing Maven properties as sbt setting, and then translates them into sys.props
at the load time of the build.