Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test sbt resolvers

Tags:

scala

sbt

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?

like image 537
EECOLOR Avatar asked Sep 29 '15 09:09

EECOLOR


People also ask

What is resolvers in sbt?

sbt resolver is the configuration for repository that contains jars and their dependencies. for example the below is a resolver definition for a repository called Sonatype and it points at snapshot releases (dev versions) resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

Does sbt use Ivy?

By default, sbt uses the standard Ivy home directory location ${user. home}/. ivy2/ . This can be configured machine-wide, for use by both the sbt launcher and by projects, by setting the system property sbt.

How does sbt resolve dependencies?

Background. update resolves dependencies according to the settings in a build file, such as libraryDependencies and resolvers . Other tasks use the output of update (an UpdateReport ) to form various classpaths. Tasks that in turn use these classpaths, such as compile or run , thus indirectly depend on update .

What is Ivy sbt?

sbt provides an interface to the repository types available in Ivy: file, URL, SSH, and SFTP. A key feature of repositories in Ivy is using patterns to configure repositories.


2 Answers

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
like image 163
isaias-b Avatar answered Oct 01 '22 23:10

isaias-b


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.

like image 20
EECOLOR Avatar answered Oct 01 '22 23:10

EECOLOR