Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sbt: How do I resolve Maven dependencies that uses Maven properties

Tags:

maven

scala

sbt

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.

like image 513
Eugene Yokota Avatar asked Oct 16 '17 05:10

Eugene Yokota


People also ask

Is SBT better than Maven?

I recently surveyed the current state of these three tools and concluded that SBT is better suited than Maven to Scala projects' needs.

What is Ivy in SBT?

Apache Ivy is a transitive package manager. It is a sub-project of the Apache Ant project, with which Ivy works to resolve project dependencies. An external XML file defines project dependencies and lists the resources necessary to build a project.

What is a transitive dependency Maven?

Transitive Dependencies. Maven avoids the need to discover and specify the libraries that your own dependencies require by including transitive dependencies automatically. This feature is facilitated by reading the project files of your dependencies from the remote repositories specified.

What is dependencyManagement in POM xml?

It's like you said; dependencyManagement is used to pull all the dependency information into a common POM file, simplifying the references in the child POM file. It becomes useful when you have multiple attributes that you don't want to retype in under multiple children projects.


1 Answers

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.

like image 57
Eugene Yokota Avatar answered Oct 10 '22 22:10

Eugene Yokota