Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override the dependency of an sbt plugin?

I've written an sbt plugin called sbt-jumi which implements sbt integration for Jumi. Right now the sbt-jumi plugin depends on the current Jumi release.

Here is the relevant line from the plugin's build.sbt:

libraryDependencies += "fi.jumi" % "jumi-launcher" % "0.5.376" 

And a user of the plugin would add this to his project/plugins.sbt file:

addSbtPlugin("fi.jumi.sbt" % "sbt-jumi" % "0.1.0") 

Now let's say that Jumi 0.6.400 is released and it's backward compatible. How can a user of the sbt-jumi plugin configure it to use Jumi 0.6.400, without me having to release a new version of the plugin?

Here is how to do it in Maven. But how to do it in sbt?

like image 356
Esko Luontola Avatar asked Aug 05 '13 19:08

Esko Luontola


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.

Where are sbt dependencies stored?

All new SBT versions (after 0.7. x ) by default put the downloaded JARS into the . ivy2 directory in your home directory. If you are using Linux, this is usually /home/<username>/.

What is sbt dependency management?

These tools support automatic dependency management for your project. Like in almost every build system, SBT allows you to define library dependencies which are resolved automatically, so you don't have to download and package required libraries by yourself.

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

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.


1 Answers

Overriding the dependencies of plugins happens the same way as overriding normal dependencies, except that the configuration must be entered into project/plugins.sbt. Overriding dependencies is explained in Library Management. Here is a summary:

If the version you wish to use is greater than the dependency that you would get transitively, sbt will use the larger version by default. You may change the conflict manager to change the default behavior - for example this will create an error on conflict:

conflictManager := ConflictManager.strict 

In other words, this in project/plugins.sbt would work:

libraryDependencies += "fi.jumi" % "jumi-launcher" % "0.6.400" 

You may check your plugin dependencies using reload plugins and then show update. It should now show the older version as "(EVICTED)".

If the version you wish to use is lower than the default dependency, then you will need to override differently. One way is to force the dependency:

libraryDependencies += "fi.jumi" % "jumi-launcher" % "0.4.350" force() 

Another way is to use the dependencyOverrides setting:

dependencyOverrides += "fi.jumi" % "jumi-launcher" % "0.4.350" 

The difference between the two methods is that overriding doesn't introduce a direct dependency. I don't think the difference matters for plugins, but for published artifacts it has some differences.

like image 109
Esko Luontola Avatar answered Sep 22 '22 20:09

Esko Luontola