Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add native library dependencies to sbt project?

Tags:

scala

sbt

I want to add a Java library (e.g. Apache PDFBox) to an sbt project.

This is the Ivy dependency:

dependency org="org.apache.pdfbox" name="pdfbox" rev="1.8.2" 

I first tried to do the following:

resolvers += "Sonatype releases" at "http://oss.sonatype.org/content/repositories/releases/"  libraryDependencies += "org.apache.pdfbox" %% "pdfbox" % "1.8.2" 

But it gives me errors of the type

[warn] ==== public: tried [warn]   http://repo1.maven.org/maven2/org/apache/pdfbox/pdfbox_2.10/1.8.2/pdfbox_2.10-1.8.2.pom 

So I understand that with this syntax I can just manage Scala dependencies. I am sure that there is a way to manage Java dependencies, but how?

I tried to search in Google for "sbt add java dependencies" but did not find (recognize) a relevant result.

like image 408
David Michael Gang Avatar asked Nov 21 '13 13:11

David Michael Gang


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.

Which is the correct way to add dependencies in sbt file?

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 add library dependencies?

To add a dependency on a library that is an annotation processor, you must add it to the annotation processor classpath using the annotationProcessor configuration. That's because using this configuration improves build performance by separating the compile classpath from the annotation processor classpath.


1 Answers

You should replace the %% (double percent) with single one.

libraryDependencies += "org.apache.pdfbox" % "pdfbox" % "1.8.2" 

The double-percent is a convenience operator, and causes adding the _+scalaVersion postfix inside the path, which is _2.10 in your case. Single percent should fix the problem.

like image 161
Rajish Avatar answered Sep 18 '22 00:09

Rajish