Need to reset terminal after each `sbt` run when using `resolvers += sonatypeRepo`? - scala

I can compile and run from sbt with a build.sbt file, e.g.,
scalaVersion := "2.11.11"
But once I add a Sonatype repo, e.g.,
resolvers += sonatypeRepo("releases")
the terminal is not properly reset and stops to echo input. I need to call reset after each call to sbt - any ideas what's causing this? I've already tried deleting ~/.ivy2, ~/.sbt, project and target - to no avail. I'm using sbt version 1.0.0, but it also happens with 0.13.x versions.
EDIT: Just found out that version 0.13.9 does not exhibit this behavior, so this seems to be a sbt regression.

Issue has been reported and being tracked in a couple of places as https://github.com/sbt/sbt/issues/3453 and
https://github.com/sbt/sbt/issues/3482
In lieu of an official patch/hotfix from SBT you can exercise one of these workarounds for now
stty echo (terminal/bash/shell)
reset (terminal/bash/shell)
use latest sbt-extras

Related

How to upgrade Scala to a newer version from the command line?

Is there away to upgrade the installed Scala version via sbt / other command line tool?
I'm sure there is a way, but I couldn't find any after a quick search, am I missing anything?
Each SBT project specifies the version of Scala to use to compile and run its code. It defaults to being the version of Scala that SBT uses internally, but is always overridable.
E.g.
scalaVersion := "2.10.0"
As Connor Doyle mentioned, if your OS has a package system that includes Scala (some Linux distros I know of do) and you are, for some reason obligated to use that, you are pretty much at their mercy to provide a new version on a timely basis. The Scala Web Site (downloads here) provides a variety of installers and tarballs / Zip archives for every release they've made.
Mac OS X users can use HomeBrew to get up-to-date SBT and Scala.
To set the project version temporarily from the command line:
++ 2.10.4
To set the project version permanently from the command line:
set scalaVersion := "2.10.4"
session save
I just executed one command line"homebrew remove scala;homebrew install scala" to update to the latest version. Isn't this enought?
I also found this link (http://wkmacura.tumblr.com/post/11577309978/installing-specific-versions-with-homebrew) and hope it works for you.

How do I refresh updated Git dependency artifacts in SBT?

I've configured SBT (0.11.0) to pull in a GitHub project as a dependency, as per my answer on this question here.
It works fine except that I can't seem to get SBT to re-compile my Git dependency when it gets updated. In other words: if I make an update to the dependency, push to Git and reload my project's SBT and run package, then SBT does not recompile the external Git dependency when compiling my project.
I've tried creating a new branch in my Git dependency (say, forcenew) and updating the branch in my SBT project configuration to use this:
lazy val depProject = RootProject(uri("git://github.com/me/dep-project.git#forcenew"))
But even this doesn't force a refresh. I'm a bit stumped - I can't even find where SBT puts the Git project to compile it (it doesn't seem to be in ~/.sbt/ or ~/.ivy2/)...
Any help greatly appreciated!
From: https://github.com/sbt/sbt/issues/335
this should be fixed in 0.12.0, just call "sbt update"
It was fixed in 0.12.0 so sbt update is enough, but got back in 13.0 -- for now, you have to wipe dependency from ~/.sbt/staging/ manually
You likely want to clear out ~/.sbt/staging/
A quick hack you can add to your build.sbt:
def removegit = Command.command("removegit"){state =>
val home = sys.env("HOME")
val k = ("rm -rf "+ home + "/.sbt/0.13/staging/").!
state
}
commands ++= Seq(removegit)
And then sbt removegit will wipe that directory. This doesn't do anything smart like checking commits, which would be a great upgrade... The repos are being stored in ~/.sbt/0.13/staging/ on my machine, you may need to adjust that.

Create Simple Project SBT 0.10.X

(This is a follow up to sbt not creating projects correctly. The question wasn't answered.)
Basically, that question says "I don't know how to create a project under the new sbt. With the old one, I just ran sbt in a new folder and there was a guided wizard that led me through the setup."
The accepted answer does not explain how to create a new project, it just points to the documentation, which also doesn't explicitly say how to create a new project -- only how to write a build.sbt file.
So I tried first writing a build.sbt and then running sbt in the directory with the build.sbt file, but I still don't see a src directory to work with.
Could someone post a simple step-by-step (I'm assuming there are like 3 steps at most) guiding how to create a new project under sbt 0.10.X?
I found the answer I was looking for at this webpage: Scala 2.9.1, sbt 0.10 and ScalaTest step-by-step.
The high-level steps are:
mkdir my_project make a folder for your project
Create a simple my_project/build.sbt file, e.g.:
name := "A Project"
version := "0.1"
scalaVersion := "2.9.1"
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "1.6.1" % "test"
)
Create a file my_project/src/main/scala/HelloWorld.scala, where you create all the directories you need as you go (e.g. create the directory structure src/main/scala/)
object Main extends App {
Console.println("Hello World!")
}
Execute your sbt commands: e.g. sbt run
I am surprised that noone gave another solution which is the closest to the old way (as mentioned by #dsg) to create a simple project in sbt:
Just run sbt in your project directory, then issue the following commands in the sbt REPL:
> set name := "MyProject"
> set version := "1.0"
> set scalaVersion := "2.9.0"
> session save
> exit
Granted, it is only mildly useful as it will just create the build.sbt file (enough to make it a proper sbt project) with the corresponding properties set, and you might as well create the file by hand (I usually prefer to do so myself). It won't create the src directory either.
Just a few days ago np (new project) plugin to sbt was released. It intended to dealt exactly with that problem:
Initial release. Provides a minimal interface for generating new sbt
projects via,... sbt.
Basic use is to install the plugin globally and start up a new project
with
$ sbt
$ np name:my-project org:com.mypackage version:0.1.0-SNAPSHOT
This will generate a simple build.sbt project for you along with the
standard project directory structure for main and test sources.
For more advanced usage, see the project's readme for more info
You can use https://github.com/n8han/giter8 to generate project layout using various templates
In newer versions of sbt, you can just install sbteclipse:
// ~/.sbt/plugins/build.sbt
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")
then from sbt's console you can run:
eclipse with-source=true
In version 0.10.x I think this post can help you:
http://dcsobral.blogspot.fr/2011/06/very-quick-guide-to-project-creation-on.html
I've been using https://github.com/ymasory/sbt-prototype skeleton. See also my other answer.
It was the first one that just worked and I've been a quite happy with it since then.
Don't forget the recent sbt 0.13.3 new command:
Example:
First, you need sbt’s launcher version 0.13.13 or above.
Normally the exact version for the sbt launcher does not matter because it will use the version specified by sbt.version in project/build.properties; however for new sbt’s launcher 0.13.13 or above is required as the command functions without a project/build.properties present.
Next, run:
$ sbt new eed3si9n/hello.g8
....
name [hello]:
scala_version [2.11.8]:
Template applied in ./hello
This ran the template eed3si9n/hello.g8 using Giter8, prompted for values for “name” and “scala_version” (which have defaults “hello” and “2.11.8”, which we accepted hitting [Enter]), and created a build under ./hello.
Check out the GitHub repo Scala SBT Template. In particular the buildt.sbt file.
Just clone the repo, go to that directory, then call the sbt command.
$ git clone git://github.com/dph01/scala-sbt-template.git
$ cd scala-sbt-template
$ ./sbt
From inside of sbt, you can type run to execute provided code. Have fun!
An alternative way to generate the project structure using Intellij:
Create the directory for the project and include there a basic sbt file. You just need to specify the project name.
name := "porjectName"
With Intellij import the project. During the process check the options "Use auto-import" and "Create directories for empty content roots automatically"
That will create for you the basic skeleton for the sbt project.

how to configure SBT to pick the desired scala version (2.9)

While creating a project with sbt command it always prompts for the 2.7.X version of scala however I have 2.9.0 and sbt 0.7.7 installed is there a way to configure sbt to pick 2.9 by default.
If you use sbt version 0.10 instead it has changed a bit, in the build.sbt file you specify scalaVersion := "2.9.0-1" (default seem to be 2.8.1)
See Migrating from SBT 0.7.x to 0.10.x or Quick Configuration Examples. The Full configuration example shows Scala style configuration.
Threre is a ~/.sbt/plugins/ library where you store global plugins. But I do not yet know if you can define a global build properties.
In your project directory there should be a file called build.properties. There you can configure SBT to use whatever version you want. When you change the file either exit SBT or use the command reload.

How to change Scala version for sbt project?

How can I change Scala version in a sbt project?
I would like SBT to check whether the system's Scala version is correct and if it is not the case then download it.
xsbt (0.10+, including the latest 0.13.7)
Change scalaVersion in build.sbt to whatever Scala version your project should be using - see .sbt build definition.
scalaVersion := "2.10.1"
sbt:
As mentioned in RunningSBT, you can:
You can temporarily switch to another version of Scala using ++<version>.
This version does not have to be listed in your build.scala.versions property, but it does have to be in a repository or be a local Scala version you have defined.
But the CrossBuild page is more suited for what you want, as it shows in action how to change the build.scala.versions property.
So you should be able to
set build.scala.versions 2.7.7
reload
set build.scala.versions 2.8.0.RC2
reload
and each time trigger a compilation with a different Scala version.