Turn a Lift project into an sbt sub project.
Goal
I'm working on a Lift project and now want to have some background jobs for management tasks etc. I posted a question on the Lift Google Group and got an answer that I should go for sub projects.
I read an entry about sub projects on the sbt wiki, tried a bit and it seems to be working now, so I'll make a note on it.
Modify project file
My project file was like the following.
import sbt._ class LiftProject(info: ProjectInfo) extends DefaultWebProject(info) { val liftVersion = "2.2" // uncomment the following if you want to use the snapshot repo // val scalatoolsSnapshot = ScalaToolsSnapshots // If you're using JRebel for Lift development, uncomment // this line // override def scanDirectories = Nil // Add repositories here val jGitRepo = "JGit" at "http://download.eclipse.org/jgit/maven" override def libraryDependencies = Set( "net.liftweb" %% "lift-webkit" % liftVersion % "compile->default", "net.liftweb" %% "lift-mapper" % liftVersion % "compile->default", "org.mortbay.jetty" % "jetty" % "6.1.22" % "test->default", "junit" % "junit" % "4.5" % "test->default", "ch.qos.logback" % "logback-classic" % "0.9.26", "org.scala-tools.testing" %% "specs" % "1.6.6" % "test->default", "org.mockito" % "mockito-core" % "1.8.5" % "test->default", "mysql" % "mysql-connector-java" % "5.1.14", //MySQL "commons-io" % "commons-io" % "2.0.1", "org.eclipse.jgit" % "org.eclipse.jgit" % "0.10.1" withJavadoc, "commons-lang" % "commons-lang" % "2.5" ) ++ super.libraryDependencies }
I made some changes on the project file. Note that I didn't move it. It still resides in
import sbt._ class FooProject(info: ProjectInfo) extends ParentProject(info) { // These create sub directories under <project-root> lazy val core = project("core", "Project-foo core", new CoreProject(_)) lazy val web = project("web", "Project-foo web", new LiftProject(_), core) lazy val bgtasks = project("bgtasks", "Project-foo background tasks", core) override def parallelExecution = true } protected class CoreProject(info: ProjectInfo) extends DefaultProject(info) { val liftVersion = "2.2" val jGitRepo = "JGit" at "http://download.eclipse.org/jgit/maven" override def libraryDependencies = Set( "net.liftweb" %% "lift-webkit" % liftVersion % "compile->default", "net.liftweb" %% "lift-mapper" % liftVersion % "compile->default", "org.mortbay.jetty" % "jetty" % "6.1.22" % "test->default", "junit" % "junit" % "4.5" % "test->default", "ch.qos.logback" % "logback-classic" % "0.9.26", "org.scala-tools.testing" %% "specs" % "1.6.6" % "test->default", "org.mockito" % "mockito-core" % "1.8.5" % "test->default", "mysql" % "mysql-connector-java" % "5.1.14", //MySQL "commons-io" % "commons-io" % "2.0.1", "org.eclipse.jgit" % "org.eclipse.jgit" % "0.10.1" withJavadoc, "commons-lang" % "commons-lang" % "2.5" ) ++ super.libraryDependencies } protected class LiftProject(info: ProjectInfo) extends DefaultWebProject(info) { // uncomment the following if you want to use the snapshot repo // val scalatoolsSnapshot = ScalaToolsSnapshots // If you're using JRebel for Lift development, uncomment // this line // override def scanDirectories = Nil }
Basically, what I did for the project file were:
- create a new project called FooProject
- create sub projects and set dependencies for them
- move most of the stuff from LiftProject to FooProject
Move files
Maybe, at this point, I did 'sbt update' or something to make directories for the sub projects, which caused compilation errors, which I ignored.
Then, I created source directories and move some sources from the web project to the core.
[user@localhost project-root]$ mkdir -p core/src/main/scala/code/{lib,model} [user@localhost project-root]$ mkdir -p core/src/test/scala/code/{lib,model} [user@localhost project-root]$ mv web/src/main/scala/code/lib/*.scala core/src/main/scala/code/lib/ [user@localhost project-root]$ mv web/src/main/scala/code/model/*.scala core/src/main/scala/code/model/ [user@localhost project-root]$ mv web/src/test/scala/code/lib/*.scala core/src/test/scala/code/lib/ [user@localhost project-root]$ mv web/src/test/scala/code/model/*.scala core/src/test/scala/code/model/ [user@localhost project-root]$ mv web/src/main/scala/bootstrap/ core/src/main/scala/
Finished
Don't forget to run the following.
[user@localhost project-root]$ ./sbt > update > compile > : > :
That's about it. It was easier than I had thought. Now, I should work on the real task, which is creating background jobs!
If you have any questions or find any problems/mistakes, feel free to comment here (in English or Japanese).