Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

scala

sbt

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.

Now whatever I do, it persistently tries to find them built against 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?


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.

like image 896
0__ Avatar asked Aug 01 '12 22:08

0__


People also ask

Which version of Scala does sbt use?

sbt uses that same version of Scala to compile the build definitions that you write for your project because they use sbt APIs. This version of Scala is fixed for a specific sbt release and cannot be changed. For sbt 1.7. 1, this version is Scala 2.12.

How do I use sbt plugins?

If you're curious which auto plugins are enabled for a given project, just run the plugins command on the sbt console. Here, the plugins output is showing that the sbt default plugins are all enabled. sbt's default settings are provided via three plugins: CorePlugin : Provides the core parallelism controls for tasks.

Where can I find plugins sbt?

Plugins can be installed for all your projects at once by dropping them in ~/. sbt/plugins/. ~/. sbt/plugins/ is an sbt project whose classpath is exported to all sbt build definition projects.


1 Answers

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

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.

// 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
)
like image 92
Brian Hsu Avatar answered Sep 21 '22 14:09

Brian Hsu