Why is crossScalaVersion not scalaVersion? - scala

build.sbt
scalaVersion := "2.11.4"
project/build.properties
sbt.version=0.13.7
Then
> show scalaVersion
[info] 2.11.4
> show crossScalaVersions
[info] List(2.10.4)
> inspect crossScalaVersions
[info] Setting: scala.collection.Seq[java.lang.String] = List(2.10.4)
[info] Description:
[info] The versions of Scala used when cross-building.
[info] Provided by:
[info] */*:crossScalaVersions
[info] Defined at:
[info] (sbt.Defaults) Defaults.scala:237
[info] Delegates:
[info] *:crossScalaVersions
[info] {.}/*:crossScalaVersions
[info] */*:crossScalaVersions
[info] Related:
[info] */*:crossScalaVersions
It seems like crossScalaVersions should be List(2.11.4).
Look at SBT's source code, that's also what I would think.
crossScalaVersions := Seq(scalaVersion.value)
Why doesn't crossScalaVersions correspond to scalaVersion?

scalaVersion.value is context-dependent. So in Defaults.scala it's */*:scalaVersion from appConfiguration.value.provider.scalaProvider. It's the version used to compile your project's definition, including your build.sbt file (sbt 0.13.7 uses 2.10.4 scala-compiler to compile your project definitions). And that the only way as your project's definitions (including scalaVersion) isn't compiled yet when Defaults executed and crossScalaVersions defined. So, */*:crossScalaVersions depends on */*:scalaVersion not proj/*:scalaVersion.
Just compare Provided by with explicit scalaVersion := 2.11.4 inside build.sbt:
> inspect scalaVersion
[info] Setting: java.lang.String = 2.11.4
[info] Description:
[info] The version of Scala used for building.
[info] Provided by:
[info] {file:/Users/user/dev/proj/}proj/*:scalaVersion
[info] Defined at:
[info] /Users/user/dev/proj/build.sbt:1
[info] Reverse dependencies (D=derives):
[info] *:allDependencies
[info] D *:scalaBinaryVersion
[info] *:libraryDependencies
[info] *:scalaInstance
[info] *:crossScalaVersions
[info] *:update
[info] Delegates:
[info] *:scalaVersion
[info] {.}/*:scalaVersion
[info] */*:scalaVersion
[info] Related:
[info] */*:scalaVersion
And without one (just empty project):
> inspect scalaVersion
[info] Setting: java.lang.String = 2.10.4
[info] Description:
[info] The version of Scala used for building.
[info] Provided by:
[info] */*:scalaVersion
[info] Defined at:
[info] (sbt.Defaults) Defaults.scala:232
[info] Reverse dependencies:
[info] *:allDependencies
[info] *:libraryDependencies
[info] *:update
[info] *:scalaInstance
[info] Delegates:
[info] *:scalaVersion
[info] {.}/*:scalaVersion
[info] */*:scalaVersion
[info] Related:
[info] */*:scalaVersion
So, you just need to redefine */*:scalaVersion in your build.sbt:
scalaVersion in GlobalScope := "2.11.2"

Related

Where is the default value of the organizationName is coming from in sbt

sbt defines the organizationName setting as SettingKey[String] (see Keys). When starting an sbt build in an empty directory, one can inspect the default value of organizationName:
> inspect organizationName
[info] Setting: java.lang.String = default
[info] Description:
[info] Organization full/formal name.
[info] Provided by:
[info] {file:/Users/bene/workspace/sbt/test/}test/*:organizationName
[info] Defined at:
[info] (sbt.Classpaths) Defaults.scala:1174
[info] Dependencies:
[info] *:organization
[info] Reverse dependencies:
[info] *:projectInfo
[info] Delegates:
[info] *:organizationName
[info] {.}/*:organizationName
[info] */*:organizationName
So the organizationName setting defaults to "default". Now the question is, where is the default value coming from?
Although it may not be completely obvious, all the information is already there. The sbt output gives us a first hint:
[info] Defined at:
[info] (sbt.Classpaths) Defaults.scala:1174
In line 1174 in Default.scala we can see, that organizationName falls back to the value of organization. Inspecting the organization setting gives us the next hint:
> inspect organization
[info] Setting: java.lang.String = default
[info] Description:
[info] Organization/group ID.
[info] Provided by:
[info] {file:/Users/bene/workspace/sbt/test/}test/*:organization
[info] Defined at:
[info] (sbt.Classpaths) Defaults.scala:1173
[info] (sbt.Build) Build.scala:58
[info] Dependencies:
[info] *:normalizedName
[info] *:thisProject
[info] Reverse dependencies:
[info] *:organizationName
[info] *:projectId
[info] Delegates:
[info] *:organization
[info] {.}/*:organization
[info] */*:organization
Finally, in Build.scala:58 we can find the mapping from a missing organization to "default".

Why are transitive dependencies not detected?

I have Scala library based on SBT, which I publish to Maven repository:
organization := "com.mycompany"
name := "mylib"
version := "0.0.1"
scalaVersion := "2.10.6"
crossScalaVersions := Seq("2.10.6", "2.11.7")
scalacOptions ++= Seq("-feature", "-unchecked", "-deprecation")
libraryDependencies ++= Seq(
"org.scalaj" %% "scalaj-http" % "2.2.0",
"org.json4s" %% "json4s-jackson" % "3.3.0",
"org.slf4j" % "slf4j-api" % "1.7.13",
"org.slf4j" % "slf4j-simple" % "1.7.13"
)
isSnapshot := true
publishMavenStyle := true
publishTo := {
Some(s3resolver.value("My Repo", s3("mybucket")).withMavenPatterns)
}
I include this library into another project:
libraryDependencies ++= Seq(
"com.mycompany" %% "mylib" % "0.0.1"
)
Running sbt sbt-dependency dependencyTree only shows:
[info] Done updating.
[info] default:another-project_2.10:1.2 [S]
[info] +-com.mycompany:mylib_2.10:0.0.1
[info]
I'm not able to see all the 3rd party dependencies: org.scalaj, org.json4s, etc.
EDIT: Moreover, when building an assembly, these dependencies are missing from the uberjar as well.
The .pom file deployed to the Maven repository do contain all the mentioned dependencies, while ~/.ivy2/cache/com.mycompany/mylib_2.10/ivy-0.0.1.xml does not.
Running sbt about in mylib/ shows:
[info] Loading global plugins from /home/michael/.sbt/0.13/plugins
[info] Loading project definition from /home/michael/Dev/projects/mylib/project
[info] Set current project to mylib (in build file:/home/michael/Dev/projects/mylib/)
[info] This is sbt 0.13.9
[info] The current project is {file:/home/michael/Dev/projects/mylib/}mylib 0.0.1
[info] The current project is built against Scala 2.10.6
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, com.typesafe.sbteclipse.plugin.EclipsePlugin, ohnosequences.sbt.SbtS3Resolver
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.5
Running sbt about in otherproject/ shows:
[info] Loading global plugins from /home/michael/.sbt/0.13/plugins
[info] Loading project definition from /home/michael/Dev/projects/otherproject/project
[info] Set current project to otherproject (in build file:/home/michael/Dev/projects/otherproject/)
[info] Updating {file:/home/michael/Dev/projects/otherproject/}otherproject...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] This is sbt 0.13.9
[info] The current project is {file:/home/michael/Dev/projects/otherproject/}otherproject 1.2
[info] The current project is built against Scala 2.10.6
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, com.typesafe.sbteclipse.plugin.EclipsePlugin, ohnosequences.sbt.SbtS3Resolver, net.virtualvoid.sbt.graph.DependencyGraphPlugin, sbtassembly.AssemblyPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.5
Here's the output from publishing to a local directory:
[info] Loading global plugins from /home/michael/.sbt/0.13/plugins
[info] Loading project definition from /home/michael/Dev/projects/mylib/project
[info] Set current project to mylib (in build file:/home/michael/Dev/projects/mylib/)
[info] Updating {file:/home/michael/Dev/projects/mylib/}mylib...
[info] Packaging /home/michael/Dev/projects/mylib/target/scala-2.10/mylib_2.10-0.0.1-sources.jar ...
[info] Done packaging.
[info] Wrote /home/michael/Dev/projects/mylib/target/scala-2.10/mylib_2.10-0.0.1.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] :: delivering :: com.mycompany#mylib_2.10;0.0.1 :: 0.0.1 :: integration :: Sat Jan 09 16:10:20 IST 2016
[info] delivering ivy file to /home/michael/Dev/projects/mylib/target/scala-2.10/ivy-0.0.1.xml
[info] Main Scala API documentation to /home/michael/Dev/projects/mylib/target/scala-2.10/api...
[info] Packaging /home/michael/Dev/projects/mylib/target/scala-2.10/mylib_2.10-0.0.1.jar ...
[info] Done packaging.
model contains 9 documentable templates
[info] Main Scala API documentation successful.
[info] Packaging /home/michael/Dev/projects/mylib/target/scala-2.10/mylib_2.10-0.0.1-javadoc.jar ...
[info] Done packaging.
[info] published mylib_2.10 to /home/michael/Dev/projects/mylib/releases/com/mycompany/mylib_2.10/0.0.1/mylib_2.10-0.0.1.pom
[info] published mylib_2.10 to /home/michael/Dev/projects/mylib/releases/com/mycompany/mylib_2.10/0.0.1/mylib_2.10-0.0.1.jar
[info] published mylib_2.10 to /home/michael/Dev/projects/mylib/releases/com/mycompany/mylib_2.10/0.0.1/mylib_2.10-0.0.1-sources.jar
[info] published mylib_2.10 to /home/michael/Dev/projects/mylib/releases/com/mycompany/mylib_2.10/0.0.1/mylib_2.10-0.0.1-javadoc.jar
[success] Total time: 4 s, completed Jan 9, 2016 4:10:23 PM
What am I doing wrong?
Your build.sbt file contains the line
publishMavenStyle := true
According to the documentation
a POM is generated by the makePom action and published to the
repository instead of an Ivy file
I can suppose that ivy.xml is just not generated and the one that you see is a residue from a previous run, when publishMavenStyle was not (yet) set.
Since your artifact is published into the Maven repository, have you tried to remove the one from ~/.ivy2/cache/com.mycompany/mylib_2.10 and check the result of dependency tree listing?

Changing scala version of play from console

I should revert my project to scala 2.10.0, but it looks like I cannot from the console. I've tried to clean and rebuild with scalaVersion := "2.10.0" in the build.sbt, but it keeps using the 2.10.2.
How can I do something like "play scala-version 2.10.0" ? (which doesn't seem to be correct)
I know it uses the 2.10.2 because it is using scala-compiler and reflect 2.10.2
jacek:~/sandbox/play-ground/xApp
$ play
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Updating {file:/Users/jacek/.sbt/0.13/plugins/}global-plugins...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Loading project definition from /Users/jacek/sandbox/play-ground/xApp/project
[info] Set current project to xApp (in build file:/Users/jacek/sandbox/play-ground/xApp/)
_
_ __ | | __ _ _ _
| '_ \| |/ _' | || |
| __/|_|\____|\__ /
|_| |__/
play 2.2.2 built with Scala 2.10.3 (running Java 1.7.0_51), http://www.playframework.com
> Type "help play" or "license" for more information.
> Type "exit" or use Ctrl+D to leave this console.
[xApp] $ show scalaVersion
[info] 2.10.3
[xApp] $ set scalaVersion := "2.10.0"
[info] Defining *:scalaVersion
[info] The new value will be used by *:allDependencies, *:dependencyUpdatesData and 11 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to xApp (in build file:/Users/jacek/sandbox/play-ground/xApp/)
[xApp] $ show scalaVersion
[info] 2.10.0
[xApp] $ session save
[info] Reapplying settings...
[info] Set current project to xApp (in build file:/Users/jacek/sandbox/play-ground/xApp/)
[xApp] $ show scalaVersion
[info] 2.10.0
[xApp] $ about
[info] This is sbt 0.13.0
[info] The current project is {file:/Users/jacek/sandbox/play-ground/xApp/}xapp 1.0-SNAPSHOT
[info] The current project is built against Scala 2.10.0
[info] Available Plugins: com.typesafe.sbt.SbtGit, com.typesafe.sbt.SbtProguard, growl.GrowlingTests, org.sbtidea.SbtIdeaPlugin, sbtman.Plugin, np.Plugin, com.timushev.sbt.updates.UpdatesPlugin, play.Project, com.typesafe.sbteclipse.plugin.EclipsePlugin, com.typesafe.sbt.SbtNativePackager
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.3
You should see the version in build.sbt in the project afterwards.
jacek:~/sandbox/play-ground/xApp
$ cat build.sbt
name := "xApp"
version := "1.0-SNAPSHOT"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache
)
scalaVersion := "2.10.0"

Difference between scalaSource and sourceDirectories in sbt

What is the difference between scalaSource and sourceDirectories? I have a non-standard directory structure where source code lives in src/,
This line works in build.sbt:
scalaSource in Compile := file("src/")
but not
sourceDirectories in Compile := Seq(file("src/"))
Sources come in many kinds: Scala and Java, managed and unmanaged. sourceDirectories in Compile combines all of them, but you wouldn't normally want to set it directly; normally you'd set the more specific setting that applies to the particular kind of source you're trying to tell sbt the location of.
Note that baseDirectory.value / "src" would be more correct than file("src") (it works in more scenarios: subprojects, external projects, etc).
I can't tell you the whole picture, someone who worked on sbt may see this post later.
Till then, here is how I reason about this things: inspect
> inspect actual compile:scalaSource
[info] Description:
[info] Default Scala source directory.
[info] Dependencies:
[info] compile:sourceDirectory
[info] Reverse dependencies:
[info] compile:unmanagedSourceDirectories
[info] Delegates:
[info] compile:scalaSource
> inspect actual compile:sourceDirectories
[info] Description:
[info] List of all source directories, both managed and unmanaged.
[info] Dependencies:
[info] compile:unmanagedSourceDirectories
[info] compile:managedSourceDirectories
[info] Delegates:
[info] compile:sourceDirectories
[info] *:sourceDirectories
[info] {.}/compile:sourceDirectories
Now this is how I interpret this:
sourceDirectories are ... well ... completely informal ...
Lets see how this is relevant to something like compile:
> inspect compile
[info] Dependencies:
[info] compile:compile::compileInputs <----
[info] compile:compile::streams
> inspect compile:compile::compileInputs
[info] Dependencies:
...
[info] compile:compile::sources <----
...
> inspect compile:compile::sources
[info] Provided by:
[info] {file:<build-uri>}<project-id>/compile:sources
[info] Delegates:
[info] compile:compile::sources
[info] compile:sources <----
This task is delegated, we can see where we came from in Reverse dependencies with inspect actual, regular inspect woudn't show them.
> inspect actual compile:sources
[info] Description:
[info] All sources, both managed and unmanaged.
[info] Reverse dependencies:
[info] compile:doc
[info] compile:compile::compileInputs
[info] Dependencies:
[info] compile:unmanagedSources <----
[info] compile:managedSources
> inspect compile:unmanagedSources
[info] Dependencies:
[info] compile:unmanagedSourceDirectories
...
> inspect compile:unmanagedSourceDirectories
[info] Dependencies:
[info] compile:javaSource
[info] compile:scalaSource <----
[info] Reverse dependencies:
[info] compile:sourceDirectories
[info] compile:unmanagedSources
Hope this helps.

How to make sbt `console` use -Yrepl-sync?

New in Scala 2.9.1 is the -Yrepl-sync option, which prevents each REPL line from being run in a new thread:
scala -Yrepl-sync
When I run console from sbt, how do I have it pass this in?
Short answer:
set scalacOptions in (Compile, console) += "-Yrepl-sync"
How to discover this:
~/code/scratch/20110930 sbt
[info] Loading global plugins from /Users/jason/.sbt11/plugins
[info] Set current project to default-9c7c16 (in build file:/Users/jason/code/scratch/20110930/)
> inspect console
[info] Task: Unit
[info] Description:
[info] Starts the Scala interpreter with the project classes on the classpath.
[info] Provided by:
[info] {file:/Users/jason/code/scratch/20110930/}default-9c7c16/compile:console
[info] Dependencies:
[info] compile:compilers(for console)
[info] compile:full-classpath
[info] compile:scalac-options(for console)
[info] compile:initial-commands(for console)
[info] compile:streams(for console)
[info] Delegates:
[info] compile:console
[info] *:console
[info] {.}/compile:console
[info] {.}/*:console
[info] */compile:console
[info] */*:console
[info] Related:
[info] test:console
> set scalaVersion := "2.9.1"
[info] Reapplying settings...
[info] Set current project to default-9c7c16 (in build file:/Users/jason/code/scratch/20110930/)
> set scalacOptions in (Compile, console) += "-Yrepl-sync"
[info] Reapplying settings...
[info] Set current project to default-9c7c16 (in build file:/Users/jason/code/scratch/20110930/)
> console
[info] Updating {file:/Users/jason/code/scratch/20110930/}default-9c7c16...
[info] Done updating.
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :power
** Power User mode enabled - BEEP BOOP SPIZ **
** :phase has been set to 'typer'. **
** scala.tools.nsc._ has been imported **
** global._ and definitions._ also imported **
** Try :help, vals.<tab>, power.<tab> **
scala> settings
res1: scala.tools.nsc.Settings =
Settings {
-classpath = /Users/jason/code/scratch/20110930/target/scala-2.9.1/classes:/Users/jason/.sbt11/boot/scala-2.9.1/lib/scala-compiler.jar:/Users/jason/.sbt11/boot/scala-2.9.1/lib/jansi.jar:/Users/jason/.sbt11/boot/scala-2.9.1/lib/jline.jar
-d = .
-Yrepl-sync = true
-encoding = UTF-8
-bootclasspath = /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsfd.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/laf.jar:/System/Librar...