Showing posts with label sbt. Show all posts
Showing posts with label sbt. Show all posts

Wednesday, June 8, 2011

Migrating to sbt 0.10: sbt-idea-plugin

In pre-0.10 versions of sbt, you could use sbt-idea-plugin to generate IDEA projects from your SBT files. That plugin doesn't work in 0.10, but here's how to make it happen:

Create a new file ~/.sbt/plugins/project/Build.scala and put the following code in it:

import sbt._

object MyPlugins extends Build {
  lazy val root = Project("root", file(".")) 
                    dependsOn (uri("git://github.com/ijuma/sbt-idea.git#sbt-0.10"))
}

Now restart SBT and type gen-idea (this command replaces the old idea). SBT 0.10 includes any code in this directory in all projects, so any other sbt-0.10 project will immediately get this functionality.

The initial project created by idea-gen will have a separate IDEA module for the project folder. I haven't been able to get IDEA to compile anything while this module is there, so I remove the module and then mark the project as excluded in the main module.

Note that if you later make a change to your .sbt file (e.g. adding a new dependency), you need to bring the IDEA project up-to-date. To do this, open the SBT Console in IDEA, run "update" and then run "gen-idea". Your IDEA project will be brought up to date and IDEA will prompt you to reload the project. Choose 'OK' and you're good to go.

(thanks to Graham Tackley for figuring out the proper way to do this)

Update: Updated the path to ~/.sbt/plugins/project/Build.scala, as it's not necessary to configure the IDEA plugin on a per-project basis.

Migrating to sbt 0.10: Lift

The latest release of sbt (version 0.10) is utterly incompatible with build scripts from older versions of SBT. Here's how to migrate a Lift project to SBT 0.10 (these instructions work with 2.4-M1; I believe you can use earlier versions of lift, as long as you downgrade scalaVersion to 2.8.1):

  1. Rename project/ to project-old/
  2. Create a new build.sbt file in the root of your project

    name := "projname"
    
    scalaVersion := "2.9.0"
    
    seq(WebPlugin.webSettings: _*)
    
    libraryDependencies ++= Seq(
      "net.liftweb" %% "lift-webkit" % "2.4-M1" % "compile->default",
      "net.liftweb" %% "lift-mapper" % "2.4-M1" % "compile->default",
      "net.liftweb" %% "lift-wizard" % "2.4-M1" % "compile->default")
    
    
    libraryDependencies ++= Seq(
      "junit" % "junit" % "4.5" % "test->default",
      "org.mortbay.jetty" % "jetty" % "6.1.22" % "jetty",
      "javax.servlet" % "servlet-api" % "2.5" % "provided->default",
      "com.h2database" % "h2" % "1.2.138",
      "ch.qos.logback" % "logback-classic" % "0.9.26" % "compile->default"
    )
  3. mkdir -p project/plugins
  4. Create a new file project/plugins/build.sbt and put the following in it:
    resolvers += "Web plugin repo" at "http://siasia.github.com/maven2"
    
    libraryDependencies <+= sbtVersion("com.github.siasia" %% "xsbt-web-plugin" % _)

Now you're good to go.

Note that the Jetty dependency has changed. If you execute jetty-run and no output appears, make sure you changed the scope for the Jetty dependency from "test" (the correct value in older SBT's) to "jetty".

Also note that the new SBT parser appears to be newline-sensitive; make sure you keep blank lines between each setting, as in the example above.