Why does SBT 0.12.2 resolve plugins with Scala 2.9.2 and ignore scalaVersion in build.sbt? - scala

SBT 0.12.2 always attempts to resolve plugins using Scala 2.9.2 when using the %% syntax on plugin imports.
I have tried setting older versions of Scala in build.sbt, newer versions, etc. Even deleting target folder each time... nothing seems to make a difference.
name := "Game"
version := "1.0"
scalaVersion := "2.9.1" // SBT is ignoring the scala version

SBT is recursive, so you need to specify scala version for project, that build your project. Another words, you need to add appropriate scalaVersion to the plugins.sbt file.

For all plugins in your project, you set scalaVersion in project/plugins.sbt file that configures the build project definition for your project and where you define plugins.
$ cat project/plugins.sbt
scalaVersion := "2.9.3"
There's however a way to set up a more specific version of sbt and Scala for a plugin.
Instead of using addSbtPlugin that accepts a single ModuleID (constructed with % and %%), use addSbtPlugin(dependency: ModuleID, sbtVersion: String) or even addSbtPlugin(dependency: ModuleID, sbtVersion: String, scalaVersion: String), e.g.
$ cat project/plugins.sbt
// It doesn't exist and it's only for demo purposes
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.0", "0.12.2", "2.5")

Related

How to make IntelliJ scala project use Scala 2.9.2 version?

I'm trying to create jar file from scala file - which will be used for Scalatron bot (http://scalatron.github.io/)
The problem is that if I create jar file using new scala versions 2.10 - 2.13 (these are the only one's that InteliJJ allows me to use) scalatron bot doesn't work.
However I found out that downgrading to scala 2.9.2 fixes the problem (Getting Scalatron to Work (trouble with opcode)).
How to downgrade to 2.9.2 on Intellij?
SBT is fully integrated with IntelliJ Idea, so you can create a SBT project in IntlliJ and make up the build.sbt file by yourself and put in it the scala version you want, compile, package and execute with SBT
name := "scalatron"
version := "0.1"
scalaVersion := "2.9.2"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.0-SNAP3" % Test

How do I call a dependent library function from an sbt task?

I have a CLI tool written in Java which can modify some source with the added params. For example, it can rename an enum value across a whole project.
I want to write an sbt task that can run this tool from my project dir with the given params, like sbt 'enums -rename A B'. My tool can be injected to the project through the sbt dependencies.
I skimmed through the book sbt in Action looking for an answer, but those examples are not this specific.
My build.sbt (far from working):
name := """toolTestWithActivator"""
version := "1.0-SNAPSHOT"
resolvers += "Local Repository" at "file://C:/Users/torcsi/.ivy2/local"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
"tool" % "tool_2.11" % "1.0",
javaJdbc,
javaEbean,
cache,
javaWs
)
val mytool = taskKey[String]("mytool")
mytool := {
com.my.tool.Main
}
Can sbt handle this type of task/dependency structure, or do I need to do this another way?
SBT is recursive: it compiles .sbt files and .scala files under the project folder and use those to execute your build (in fact you can see sbt as a library that helps you producing builds).
So, as you need your library to define a task, that one is a dependency of your build.sbt file (and not a dependency of your project).
To declare that the build.sbt file depends on your library, just create a ".sbt" file in the project folder; example:
project/dependencies.sbt
libraryDependencies += "tool" %% "tool" % "1.0"
and in build.sbt add:
val mytool = taskKey[Unit]("mytool")
mytool := {
com.my.tool.main(Array())
}
Some comments:
be careful with the scala version used: as sbt 0.13 is compiled with scala 2.10; your library should also be compiled for scala 2.10 (the package should be tools_2.10 ). And the new sbt 1.0 is compiled with scala 2.12.
I used the %% notation, so that sbt adds by itself the expected scala version.
I supposed your cli tool defines a classic java main method (or the scala equivalent). So, the argument should be an Array of String (here an empty one) and it returns Unit (void in java).
Some reference to understand the solution:
http://www.scala-sbt.org/0.13/docs/Organizing-Build.html

How to determine what dependency is forcing the scala version to be 2.10 when scalaVersion is set to 2.11.2

I'm trying to build the lunatech-securesocial-poc project with scala 2.11.2 and I've updated the scalaVersion in projects/Build.scala. This project depends on securesocial, which I've built locally with 2.11.2 and named its artifact version master-SNAPSHOT. I've updated the dependency in lunatech-securesocial-poc's project to use this version of securesocial. However, SBT (activator) fails to compile because it is looking for ws.securesocial#securesocial_2.10;master-SNAPSHOT. How can I find out what is causing the scala version to be overridden to 2.10. I want 2.11.2. Obviously some dependency is forcing it, but I want to find out what that dependency is, and fix it.
I've tried adding:
dependencyOverrides += "org.scala-lang" % "scala-library" % scalaVersion.value
evictionWarningOptions := EvictionWarningOptions.default.withWarnTransitiveEvictions(true).withWarnDirectEvictions(true).withWarnScalaVersionEviction(true)
ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }
to my Build.scala and I'm using SBT version 0.13.7. I don't see why it is so hard for SBT to just abort and tell me that XXX dependency is preventing it from using 2.11.2 and requiring 2.10.
Anyone?
You can use sbt-dependency-graph plugin to find this out.
The issue turned out to be in my Build.scala. While I defined scalaVersion and used it in setting up dependencies, I didn't pass a setting to the Project that overrode the default scalaVersion, which evidently is the one used to build activator (2.10.4). So despite thinking I had set scalaVersion, I hadn't really.

Play Scala SBT not showing dependency in Reference Library in Eclipse

I created a new project using Play Scala and Eclipse. Added Squeryl dependency and see that it's been pulled during compile time. Confirmed it's present in .ivy2/cache/org.squeryl directory but eclipse project is not able to pull it up and causing compilation for import.
build.sbt
name := """registration"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
ws,
"org.squeryl" % "squeryl_2.10" % "0.9.6-RC2"
)
It looks like squeryl doesn't have a binary readily available for Scala 2.11 yet according to http://www.squeryl.org/getting-started.html
So if you want to use a pre-compiled version of this library you must change your scala version to 2.10.4.
All versions of squeryl available can be found at: http://mvnrepository.com/artifact/org.squeryl
I had a similar case using eclipse.
Select Project --> Clean to clean your workspace and build it again if you have not checked "Build Automatically".
If its still not visible please refresh the package explorer (or just the 'Referenced Library') with F5.

how to configure 2.9.1 in org.scala-sbt#sbt_2.9.1;0.12.3

I am trying a very simple sbt example; when I compile it with sbt, and always get the following error:
org.scala-sbt#sbt_2.9.1;0.12.3: not found
I found a build.properties file under project folder, where I could change the 0.12.3 part; for example, after I changed it to 0.11.3, it will succeed until another inompatible issue; However, I want to know how to change sbt_2.9.1 to, say, sbt_2.9.2; I don't find a configuration file, and even I update the sbt to the latest version 0.12.3, still no luck.
my build.sbt file:
organization := "com.typesafe.slick"
name := "slick-examples"
version := "1.0.1-RC1"
scalaVersion := "2.10.1"
scalacOptions += "-deprecation"
anyone please help me.
The Scala version sbt is using internally and the one used for your project are totally independent. Which sbt launcher are you using? Make sure you are using an sbt.version property that works for your sbt launcher.
Again, no need to configure the Scala version for your project at that level. Write a build.sbt file and set scalaVersion to, e.g. 2.10.1 (assuming you use sbt 0.12.x): scalaVersion := 2.10.1