Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add scalax.io as dependency in SBT?

Tags:

sbt

I want to use scalax.io._ to manipulate file operations with SBT.

When I ran it, I got the error message showing scalax is not found.

>sbt run
import scalax.io._
[error]        ^
[error] iotest.scala:49: not found: object scalax

How to find the library dependency for this particular one?

A more general question, how to obtain the library dependency information for any library? For example, if I need use actor in scala, I need specify a library dependency. How to find the library dependency?

like image 994
derek Avatar asked Dec 30 '13 07:12

derek


People also ask

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

Library dependencies can be added in two ways: unmanaged dependencies are jars dropped into the lib directory. managed dependencies are configured in the build definition and downloaded automatically from repositories.

How do we specify library dependencies in sbt?

You can use both managed and unmanaged dependencies in your SBT projects. 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.

What is transitive dependency in sbt?

SBT Dependencies SBT is the most usual build tool for Scala projects. As a project gets more complex, it will increase the number of dependencies. And each dependency brings other dependencies, called transitive dependencies. Eventually, a project can suffer from the JAR dependency hell.


1 Answers

"the library dependency information for any library" is part of the library's documentation and the author(s) is supposed to publish the info for different project management tools, sbt including. After all, what would be the purpose of developing a library that's hard to use?

Use http://search.maven.org/ to search for a library, and when you search for scala-io you'll get a list of available scala-io libraries.

Since I've never worked with the library I copied the ScalaIOExample example from Scala IO Documentation to have a working example. It needs the scalax.io and scalax.file packages that are distributed as scala-io-file artifact. Searching for the artifact leads to Artifact Details For com.github.scala-incubator.io:scala-io-file_2.10:0.4.2 with information on how to use it with Scala SBT in Dependency Information section.

With this, I created the following build.sbt in a sbt project:

scalaVersion := "2.10.3"

libraryDependencies += "com.github.scala-incubator.io" %% "scala-io-file" % "0.4.2"

It will add scala-io-file_2.10-0.4.2.jar to classpath and executing run in the project gives the following results:

$ sbt run
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/sandbox/stackoverflow/sbt-scala-io/project
[info] Set current project to sbt-scala-io (in build file:/Users/jacek/sandbox/stackoverflow/sbt-scala-io/)
[info] Running ScalaIOExample
Not interrupting system thread Thread[Keep-Alive-Timer,8,system]
Not interrupting system thread Thread[Keep-Alive-SocketCleaner,8,system]
[success] Total time: 5 s, completed Dec 31, 2013 11:16:42 PM
like image 71
Jacek Laskowski Avatar answered Oct 12 '22 23:10

Jacek Laskowski