Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude test dependency resolution from `sbt compile`

Tags:

scala

sbt

ivy

When running sbt compile, dependencies marked as test are still resolved even though they are not later included later in compilation. It seems like this should only happen during the test:compile task. Is there a way to exclude test dependencies from being resolved and downloaded during the compile task?

Here is an example with the org.mockito#mockito-all dependency. I have it declared as test-only:

"org.mockito" %  "mockito-all" % "1.9.0" % "test"

However, when (clearing it from my local Ivy cache and) running sbt compile, it gets needlessly downloaded:

$ sbt compile [info] Loading global plugins from /Users/rbrainard/.sbt/plugins [info] Loading project definition from /Users/rbrainard/Development/spitball/project [info] Set current project to spitball (in build file:/Users/rbrainard/Development/spitball/) [info] Updating {file:/Users/rbrainard/Development/spitball/}spitball... [info] Resolving org.mockito#mockito-all;1.9.0 ... [info] downloading http://repo1.maven.org/maven2/org/mockito/mockito-all/1.9.0/mockito-all-1.9.0.jar ... [info] [SUCCESSFUL ] org.mockito#mockito-all;1.9.0!mockito-all.jar (2075ms) [info] Done updating. [success] Total time: 7 s, completed May 28, 2014 4:51:20 PM

like image 766
ryanbrainard Avatar asked Oct 20 '22 07:10

ryanbrainard


1 Answers

In sbt the update task resolves all dependencies for all configurations. Sbt makes use of Ivy, which promotes a very interesting "configuration" aspect to be able to separately resolve disparate classpaths at the same time.

Sbt is not only resolving your test classpath, but also runtime, the scala-tools (compiler, scaladoc, repl) and more.

Please read: https://ant.apache.org/ivy/history/latest-milestone/terminology.html for more information on the design of Ivy, which is why sbt attempts to do all resolution at once for all configurations.

like image 161
2 revs, 2 users 89% Avatar answered Oct 28 '22 23:10

2 revs, 2 users 89%