I'm new to SBT and am unsure how to get a project started. Can someone point me to a beginner's guide to creating a Hello World type project, or give me some clues?
My preferred IDE is IDEA. I have run sbt-idea
according to the instruction on the IDEA Plugins page. At the moment I'm a bit confused because
- there are no source folders created - where / how am I supposed to create them and how will SBT know where to look?
- why is it trying to use Scala 2.8.1, when I have already put
scalaVersion := "2.9.0"
in thebuild.sbt
file? This means IDEA doesn't recognizeobject HelloWorld extends App {}
. - the instructions on the plugins page above suggest changing the Before Launch options of "a Run Configuration (including the Default Run Configuration)". There are 13 different default configurations for different things listed - which one to change? Should I be creating a new one? Are these default configurations just for this project or will it adversely affect all my other projects that don't use SBT?
Thanks.
I wrote a very quick guide about it. It is not intended to be an SBT guide -- there's no way to beat the SBT Wiki for that. It would be pointless too, since one can just contribute to the wiki itself.
But, I think my very quick guide will get you up and running as you wish.
As for directory creation, the answer I got was that SBT expects the IDE to handle that -- I don't really like that attitude, but a plugin can do the job. You'll see I install the sbt eclipse plugin just so it will do it for me, even though I use IDEA myself (when I use an IDE).
Also, note that, ideally, you use both the IDEA plugin for SBT that you mentioned, and the SBT plugin for IDEA. See here for the list of plugins.
Unless the IDEA plugin has evolved a lot, you really need to generate an IDEA configuration from SBT iself -- IDEA won't "read" your configuration. That's what the SBT plugin for IDEA does. Install it, and
sbt gen-idea
. I expect that will solve the problem you mentioned.Note, however, that the version of Scala you use to compile your project and the version of Scala that SBT uses for itself are different indeed. This is not a problem, it is as expected. I'm not sure from your question if the 2.8.1 version you mentioned is the one used by SBT, or one used by IDEA -- or even one used to compile your project, indicating that something is not working.
Where did you put the example you mentioned anyway? You should follow maven-style directory hierarchy, which means putting it on
src/main/scala/
, and possibly a subdirectory of that related to the package, if you follow Java convention as well.And try to compile with sbt, to make sure that is working, before proceeding to IDEA.
I normally put the src into a folder "src/test/scala" and "src/main/scala". sbt-idea will add this folders ase source/test folder in idea.
sbt itself needs Scala 2.8.1 but this version has nothing to do with the version of your code. If you try to compile some source sbt will download Scala 2.9.0.
This worked for me:
First get sbt and the gen-idea plugin going...
sbt
command. This should download the scala libraries and create a 'project' and 'target' directories.Create a new file 'build.sbt' in this directory with the following lines, as described on the sbt-idea plugin Github wiki:
Change back to your main project directory such as ~/myCode/myNewProject. Run
sbt
. It should download the gen-idea plugin.gen-idea
command. It should create the IDEA project directories. For me, it also emits copious warnings.Now get the IDEA SBT console plugin going...
Make up a new 'build.sbt' file and put it in ~/myCode/myProject (or whatever you called it). Since I am just figuring out sbt, mine is simple so far - just nominates scalatest as a dependency and uses Scala 2.9:
Enter the
reload
command in the SBT console at the bottom of the IDEA screen. It should download scalatest and Scala 2.9 for you. Maybe you need to run 'update' too.