Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve a non-jar (dll/jnilib) library dependencies in sbt?

Tags:

scala

sbt

In a SBT build.sbt project file, is it possible to retrieve library dependencies which are not bundled as jar?

In my case, I am trying to use QTSampledSP which requires .dll and .jnilib libraries.

like image 554
Mark Jayxcela Avatar asked Dec 30 '13 15:12

Mark Jayxcela


People also ask

How do we specify library dependencies in sbt?

The libraryDependencies key Most of the time, you can simply list your dependencies in the setting libraryDependencies . It's also possible to write a Maven POM file or Ivy configuration file to externally configure your dependencies, and have sbt use those external configuration files.

Where are sbt dependencies stored?

If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.

How do I run a JAR file in sbt?

A JAR file created by SBT can be run by the Scala interpreter, but not the Java interpreter. This is because class files in the JAR file created by sbt package have dependencies on Scala class files (Scala libraries), which aren't included in the JAR file SBT generates.

What is sbt dependency management?

Like in almost every build system, SBT allows you to define library dependencies which are resolved automatically, so you don't have to download and package required libraries by yourself.


1 Answers

To download the artifact, you need to make Ivy (and hence sbt) explicitly aware of the DLL artifact. Add the following to build.sbt in your project.

lazy val QtSampledJniLibArt = Artifact("qtsampledsp-osx", "jnilib", "jnilib")

libraryDependencies += "com.tagtraum" % "qtsampledsp-osx" % "0.9.6" artifacts(QtSampledJniLibArt)

resolvers += "beatunes" at "http://www.beatunes.com/repo/maven2"

Then you need to tell sbt to pay attention to these artifacts (again build.sbt):

classpathTypes ++= Set("jnilib", "dll")

By default, sbt will only add a few types into the classpath (and jnilib and dll are not amongst them).

[sbt-0-13-1]> help classpathTypes
Artifact types that are included on the classpath.
[sbt-0-13-1]> show classpathTypes
[info] Set(eclipse-plugin, bundle, hk2-jar, orbit, jar)

Since these DLLs/jnilibs are needed on the classpath to run correctly, the above setting classpathTypes where you add the additional types will correct things as you can see below (don't forget to reload when in sbt console).

[sbt-0-13-1]> show classpathTypes
[info] Set(eclipse-plugin, bundle, hk2-jar, jnilib, orbit, jar, dll)

If you need to look in more detail at these files, check out the update report (from the update task) where you can inspect all configurations/modules/artifacts. Run show update in sbt console and look at the files in target/resolution-cache/reports.

like image 82
3 revs, 2 users 56% Avatar answered Sep 28 '22 16:09

3 revs, 2 users 56%