8

On my local machine I have an ivy cache that has been filled by working on multiple projects.

A library X is loaded using resolver Y in project A. This same library X is used in project B, no problems resolving this library because it's in my local cache.

When one of my colleagues loads project B he get's the error that library X could not be resolved. The problem: resolver Y is missing.

How can I test if my sbt project has a complete set of resolvers to resolve all dependencies without removing my ivy cache?

9
  • To clarify, your question: You want to see on project B that resolver Y is missing, even though you got the necessary dependencies in your local cache? Am I right?
    – isaias-b
    Oct 11, 2015 at 10:44
  • If I understood you correctly, you would need something like the sbt update task (being part of the list of default tasks) but explicitly telling sbt not to use any caching to resolve the dependencies. On SNAPSHOT dependencies this seems to be the case as default given this answer. The first comment also points out that it might be possible to mitigate this restriction with the optional def changing() on the dependency declaration site.
    – isaias-b
    Oct 11, 2015 at 10:52
  • You could inspect the Caching and Resolution options, as proposed by this answer
    – isaias-b
    Oct 11, 2015 at 11:05
  • @isi On your first question: yes, you are right.
    – EECOLOR
    Oct 15, 2015 at 15:43
  • @isi The caching and resolution options did not provide any help.
    – EECOLOR
    Oct 15, 2015 at 19:26

4 Answers 4

2
+200

Another even more elegant solution would be to investigate the SBT sources if it is easily possible to setup this behavior as a separate task. The necessary steps could be the same as in my other answer.

  1. Extract parameter sbt.ivy.home from update task and provide a parameterized overload for it (if this is possible)
  2. Define new task testDependencies see documentation
  3. Create tempDirectory
  4. Call update(tempDirectory)
  5. Gather results
  6. Remove tempDirectory
  7. Promote results
  8. Provide a pull request ;) or an sbt plugin
3
  • This sounds like a great idea, I'll test it out
    – EECOLOR
    Oct 16, 2015 at 23:14
  • It seems ivyPaths := new IvyPaths(baseDirectory.value, Some(baseDirectory.value / "tmp-cache")) does the trick. Now I just need to figure out how to create a custom task that runs update with that setting.
    – EECOLOR
    Oct 16, 2015 at 23:51
  • Thank you for your help. I added a command as an answer but assigned the bounty to your answer.
    – EECOLOR
    Oct 17, 2015 at 0:30
2

This command allows you to find if you are missing any updates for the current project. Note that this will not discover any missing resolvers for your plugins.

commands += Command.command("testUpdate") { state =>
  val base = baseDirectory.value
  val newState = Project
    .extract(state)
    .append(Seq(ivyPaths := new IvyPaths(base, Some(base / "tmp-cache"))), state)
  val (s, _) = Project
    .extract(newState)
    .runTask(update, newState)
  s
}

It could be expanded by removing the directory afterwards.

3
  • Congratulations and thanks ;) but I would have a slight addition due to common conventions. sbt tasks lists a list of available tasks which shows that the predefined tasks all use camel casing for their names. Using hyphens strongly reminds me using maven. Having hyphens in names might even be an issue when calling the task within a build.scala file.
    – isaias-b
    Oct 17, 2015 at 0:35
  • @isi I have changed the name based on your suggestion. As a side not: be careful not to confuse commands with tasks.
    – EECOLOR
    Oct 17, 2015 at 9:21
  • Regarding your side note: As I was reading your comment and diving into the documentation I was clear that this is not so easy to achieve and I issued a question to clarify this.
    – isaias-b
    Oct 17, 2015 at 13:58
1

I found an admittedly simple but also a bit hacky and nonetheless working solution. As described here you can setup the ivy home directory. After setting this up it will provoke the sbt instances on your system to update all dependencies, due to a fresh cache directory. When all dependencies could be resolved you could inspect the std out for some string indicating success. Like Done updating. and delete the temporal folder afterwards. Caution, a fresh resolve from scratch might take a while! ~5min 100mBit/s and using an SSD drive

Instead of defining the sbt.ivy.home variable system wide and in an somewhat unportable fashion i would recommend to use the less system invasive option of defining the sbt.ivy.home variable within the environment variable SBT_OPTS on your local command/terminal session. On Windows this looks as follows:

C:\Users\isi\Projects\learning\sbt-test-dependencies>SET SBT_OPTS=-Dsbt.ivy.home="C:\path\to\your\temp\directory"

C:\Users\isi\Projects\learning\sbt-test-dependencies>sbt
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading project definition from C:\Users\isi\Projects\learning\sbt-test-dependencies\project
[info] Updating {file:/C:/Users/isi/Projects/learning/sbt-test-dependencies/project/}sbt-test-dependencies-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] downloading https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe.sbteclipse/sbteclipse-plugin/scala_2.10/sbt_0.13/4.0.0/jars/sbteclipse-plugin.jar ...
[info]  [SUCCESSFUL ] com.typesafe.sbteclipse#sbteclipse-plugin;4.0.0!sbteclipse-plugin.jar (4783ms)
...
[info] downloading https://jcenter.bintray.com/org/scala-lang/jline/2.10.5/jline-2.10.5.jar ...
[info]  [SUCCESSFUL ] org.scala-lang#jline;2.10.5!jline.jar (419ms)
[info] downloading https://jcenter.bintray.com/org/fusesource/jansi/jansi/1.4/jansi-1.4.jar ...
[info]  [SUCCESSFUL ] org.fusesource.jansi#jansi;1.4!jansi.jar (325ms)
[info] Done updating.
[info] Set current project to sbt-test-dependencies (in build file:/C:/Users/isi/Projects/learning/sbt-test-dependencies/)/Users/isi/Projects/learning/sbt-test-dependencies/)

The output can be piped to lets say grep and the exit code can be used for further processing. Notice, that the console output above was produced using the interactive sbt command, a similar output is generated using the non interactive sbt update command.

1

There is now an SBT plugin available, called SBT dirty money, to add additional functionality for tackle this problem. Although you have to execute an extra command.

2
  • "without removing my ivy cache" - plugin clears the dependencies from the cache - since you will be adding them directly again to test it won't be a problem though.
    – EECOLOR
    Sep 9, 2016 at 7:47
  • Yep, it means you have to download everything again. Making this part of the release step ensures the resolution, but it does adds several minutes of build time. What is more important, making sure that all is resolved or a quick build which might fail. When using build servers you might want to create an extra step for test and acceptance to test the resolvers and skip it for production. But this is entirely your own choice.
    – Jork
    Sep 12, 2016 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.