Xiaohe Dong
Xiaohe Dong

Reputation: 5023

different import handling strategy for library and plugin dependency in sbt

Recently, I found out an interesting issue of sbt. It is very hard for me to describe it in several sentences, so here are several steps what I have done.

I have some kind of scala tasks for deployment. I published it into our local nexus repo, so several projects can use it. Here is the screenshot for internal nexus repo

enter image description here

Thus, I put it into the build.sbt file.

"sbt.liquibase" % "**sbt-liquibase-deploy_2.10" % "1.0-3"**

In this case, I have to specify scala version 2.10, If I reload to use

"sbt.liquibase" % "**sbt-liquibase-deploy" % "1.0-3"**

It failed on unresolved dependency, I am fine with that. However, after that, I thought that this task should be a plugin, so I can use it in the build.sbt file. I add setting sbtPlugin:true into task. The artifact changes from sbt-liquibase-deploy_2.10 to sbt-liquibase-deploy_2.10_0.13 after I published it. Basically, the sbt version is appended.

When I try to addPlugin to use these code

addSbtPlugin("sbt.liquibase" % "sbt-liquibase-deploy_2.10" % "1.0-3")

It failed on unresolved dependency

addSbtPlugin("sbt.liquibase" % "sbt-liquibase-deploy_2.10_0.13" % "1.0-3")

It failed on unresolved dependency as well

but if I dont use scala and sbt version at all, it is fine.

addSbtPlugin("sbt.liquibase" % "sbt-liquibase-deploy" % "1.0-3") //Successful

I have 3 questions.

  1. why library dependency needs scala version while plugin dependency does not. It took several hours to fix it. It is not consistent.

  2. when I use sbt publish task, the scala version and sbt version are appended, can I customize it to get rid of it.

  3. This is totally unrelated, Is resolvers in build.sbt and plugins.sbt same or different. The reason I ask looks like when I try to sbt reload, resolvers in plugins.sbt is verified, while sbt update, resolver in build.sbt is verified

Any answer or solution is appreciated. :)

Upvotes: 0

Views: 263

Answers (1)

lpiepiora
lpiepiora

Reputation: 13749

  1. Plugins are compiled against specific sbt version, which uses specific Scala version. Therefore addSbtPlugin will add an sbt and Scala version under the hood.

  2. You should really not be doing it, because of the first. Your plugin is compiled against a specific version of Scala and sbt, and therefore this values are appended.

  3. Sbt is recursive, and resolvers defined in build.sbt are defined for building your project, and resolvers in project/plugins.sbt are used for building your project's build definition.

Upvotes: 2

Related Questions