如何通知 SBT 为插件使用特定的 Scala 版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11768730/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 04:24:54  来源:igfitidea点击:

How to inform SBT to consume specific scala version for plugins?

scalasbt

提问by 0__

Now I somehow messed up my global sbt plugins (~/.sbt/plugins/build.sbt). They were always fine retrieved against Scala 2.9.1 which seems to be the version that sbt 0.11.3 wants, and all the plugins (sbt-gpg-plugin, sbt-idea-plugin) are published against 2.9.1.

现在我以某种方式搞砸了我的全局 sbt 插件 ( ~/.sbt/plugins/build.sbt)。它们总是可以针对 Scala 2.9.1 进行检索,这似乎是 sbt 0.11.3 想要的版本,并且所有插件(sbt-gpg-plugin、sbt-idea-plugin)都是针对 2.9.1 发布的。

Now whatever I do, it persistently tries to find them built against 2.9.2:

现在无论我做什么,它都会不断地尝试找到它们是针对 2.9.2 构建的:

[warn]  Note: Some unresolved dependencies have extra attributes.  Check that these dependencies exist with the requested attributes.
[warn]      com.github.mpeltonen:sbt-idea:1.0.0 (sbtVersion=0.11.3, scalaVersion=2.9.2)
[warn]      com.jsuereth:xsbt-gpg-plugin:0.6 (sbtVersion=0.11.3, scalaVersion=2.9.2)
...
[error] {file:...}default-50be6e/*:update: sbt.ResolveException: unresolved dependency: com.github.mpeltonen#sbt-idea;1.0.0: not found

How can I fix this, so sbt retrieves the plugins for Scala 2.9.1 as before?

我该如何解决这个问题,让 sbt 像以前一样检索 Scala 2.9.1 的插件?



For the sake of completeness, this is how my files look after the suggestions:

为了完整起见,这就是我的文件处理建议的方式:

// project-home/build.sbt
scalaVersion := "2.9.2"
...

?

?

// project-home/project/plugins.sbt
resolvers += "less is" at "http://repo.lessis.me"

addSbtPlugin( "me.lessis" % "ls-sbt" % "0.1.1" )

scalaVersion := "2.9.1"  // "just in case it helps"

?

?

// ~/.sbt/plugins/build.sbt
scalaVersion := "2.9.1"  // "just in case it helps"

resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"

resolvers += Resolver.url( "sbt-plugin-releases", url( "http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases" ))( Resolver.ivyStylePatterns )

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.0.0")

addSbtPlugin( "com.jsuereth" % "xsbt-gpg-plugin" % "0.6" )


What is even worse, the problem persists, even after I removed~/.sbt/plugins/build.sbt. So there are no more references (at least visible to me) to either sbt-idea or xsbt-gpg-plugin. Still I cannot compile any project any more, because sbt still tries to find those two plugins. Epic fail.

更糟糕的是,即使我删除了~/.sbt/plugins/build.sbt. 因此,不再有对 sbt-idea 或 xsbt-gpg-plugin 的引用(至少对我来说是可见的)。我仍然无法再编译任何项目,因为 sbt 仍然试图找到这两个插件。史诗失败。

采纳答案by Brian Hsu

You could provide the Scala version of plugin. I didn't use ~/.sbt/, but I think it will works too.

您可以提供 Scala 版本的插件。我没有使用 ~/.sbt/,但我认为它也可以。

The following is my project configuration using Scala 2.9.2 as my project compiler, and using some pluign that are compiled from Scala 2.9.1. Since Scala 2.9.1 and Scala 2.9.2 is binary compatible, I don't encounter any problem yet.

以下是我的项目配置,使用 Scala 2.9.2 作为我的项目编译器,并使用一些从 Scala 2.9.1 编译的插件。由于 Scala 2.9.1 和 Scala 2.9.2 是二进制兼容的,所以我还没有遇到任何问题。

// MyProject/build.sbt

name := "MyProject"            

version := "0.1"            

scalaVersion := "2.9.2"     

The following is plugin configuration:

以下是插件配置:

// File: MyProject/project/plugins.sbt

import sbt._

import Defaults._

resolvers += Resolver.url("sbt-plugin-releases",
  new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(
    Resolver.ivyStylePatterns)


// Resolved to: 
//
//  http://..../com.untyped/sbt-less/scala_2.9.1/sbt_0.11.3/0.4/jars/sbt-less.jar 
//
libraryDependencies += sbtPluginExtra(
    m = "com.untyped" % "sbt-less" % "0.4", // Plugin module name and version
    sbtV = "0.11.3",    // SBT version
    scalaV = "2.9.1"    // Scala version compiled the plugin
)

回答by Richard Sitze

Some references:

一些参考:

SBT plugins are versioned to the scala version they were built with.

SBT 插件版本化为它们构建时使用的 scala 版本

You're not the only one...Again, no answers.

你不是唯一的……再一次,没有答案。

And another case study, this may have answers.

另一个案例研究,这可能有答案

A possibly relevant quote? " Remember to also remove the project/plugins -directory, because if the directory exists, project/plugins.sbt is ignored."

一个可能相关的报价?" 记住还要删除 project/plugins -目录,因为如果该目录存在,project/plugins.sbt 将被忽略。"

回答by Ravindra

You can also specify sbtVersionand scalaVersion. There is an overloaded addSbtPlugin-

您还可以指定sbtVersionscalaVersion。有一个超载addSbtPlugin-

addSbtPlugin(dependency : sbt.ModuleID, sbtVersion : scala.Predef.String, scalaVersion : scala.Predef.String)

回答by 0__

Ok, I went back to all the events that could have led to this. And because I found that other projects were still building, I started to understand that the problem with this particular project Bwas that it appeared that the two plugins were regular dependenciesof project Awhich it depended on.

好吧,我回到了所有可能导致这种情况的事件。而且因为我发现其他项目仍在构建中,我开始明白这个特定项目的问题B在于,这两个插件似乎是它所依赖的项目的常规依赖A

When sbt refused to acknowledge the presence of the GPG plugin which I uncommented in ~/.sbt/plugins/build.sbt, I renamed that fileto ~/.sbt/plugins.sbt, and back again. That intermediate position somehow meant that the plugins were not any more plugins (despite being added as addSbtPlugin), but regular dependencies for the project Awhen I publish that.

当 sbt 拒绝承认我在 中取消注释的 GPG 插件的存在时~/.sbt/plugins/build.sbt,我将该文件重命名~/.sbt/plugins.sbt,然后再次返回。这个中间位置在某种程度上意味着插件不再是插件(尽管被添加为addSbtPlugin),而是A当我发布它时项目的常规依赖项。

I tried to find that messed up A's ivy.xmlacross all known Ivy2 cache directories. It was not possible to find the one that sbt was obviously seeing.

我试图找到那个搞砸Aivy.xml所有已知Ivy2缓存目录。不可能找到sbt明显看到的那个。

Long story, short answer: I had to bump the version of Aartificially to get rid of the wrong ivy.xmlcached somewhere in a hidden place. That forced sbt to re-find Awith the correct ivy.xml(not depending any more on the plugins).

长话短说:我不得不A人为地碰撞版本以摆脱ivy.xml隐藏在某个地方的错误缓存。这迫使 sbt 重新找到A正确的ivy.xml(不再依赖于插件)。

Now I'm just worried what happens if I put my global plugin settings into place :-#

现在我只是担心如果我将全局插件设置放到位会发生什么:-#



Future advise: Never ever ever put anything into ~/.sbt/plugins.sbt. If you need sbt to understand that you changed ~/.sbt/plugins/build.sbt: Reboot your computer. Don't touch any file.

未来的建议:永远不要将任何东西放入~/.sbt/plugins.sbt. 如果您需要 sbt 来了解您已更改~/.sbt/plugins/build.sbt:重新启动计算机。不要触摸任何文件。