Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a library dependency in the definition of an sbt task?

Tags:

scala

sbt

I am defining an sbt task that needs to call code in a library. Here is a build.sbt file with what I've tried so far:

libraryDependencies ++= Seq("com.some.company" %% "some-lib" % "1.0.0")

val doSomething = taskKey[Unit]("does something")

doSomething := {
  import com.some.company.function
  function()
}

The imports do not work. How do I define a task that depends on code in an external library?

like image 489
mushroom Avatar asked Jan 16 '16 15:01

mushroom


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.

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.

What is provided dependency in sbt?

The “provided” keyword indicates that the dependency is provided by the runtime, so there's no need to include it in the JAR file. When using sbt-assembly, we may encounter an error caused by the default deduplicate merge strategy. In most cases, this is caused by files in the META-INF directory.


1 Answers

To build the .sbt file itself in the root directory, SBT uses information in the project directory. So put a build.sbt in the project directory and set the libraryDependencies key there:

libraryDependencies ++= Seq("com.some.company" %% "some-lib" % "1.0.0")

So, to clarify, you now have two build.sbt files:

  1. ./build.sbt
  2. ./project/build.sbt
like image 180
Ajay Padala Avatar answered Oct 01 '22 09:10

Ajay Padala