k4200’s notes and thoughts

Programmer side of k4200

Change "jetty-port" of xsbt-web-plugin

This entry is going to be short.

No more "override jettyPort"

I wrote an article about Lift + sbt 0.10 (+ xsbt-web-plugin) about two months ago. I got a project working, but couldn't figure out some issues.

One of them was changing the listening port of Jetty, which defaults to 8080. It was easy for sbt 0.7. You just need to override jettyPort in your project class. There's an entry on the old sbt wiki, and also a lot of information about it on the web. But, sbt 0.10 is different.

SettingKey in sbt 0.10

Let me show you the code first. Below is a part of my project file. The key is "SettingKey".

  val jettyPort = SettingKey[Int]("jetty-port")

  lazy val web = Project ("web", file ("web"),
           settings = buildSettings ++
                      webSettings ++
                      Seq (resolvers := Seq(webPluginRepo, jettyRepo),
                           libraryDependencies := allDeps ++ webPluginDeps,
                           jettyPort := 7080)) dependsOn (core)

In sbt 0.10, settings, tasks etc. almost everything is a Key. SettingKey[Int]("jetty-port") is defined in com.github.siasia.WebPlugin, and we want to "override" it, and the above code does that.

Note that our "jettyPort := 7080" follows webSettings, which contains the original "jetty-port". If webSettings appeared after "jettyPort := 7080", the default setting (8080) would "win".

It took me two hours or so to get to the point.

Resources

I attended a study session about sbt in Shibuya, Tokyo today, and the guy who had given a presentation gave me some hint. The guy also said that the most important resource about sbt is its wiki on Github. The next comes the mailing list.

He also mentioned that sbt source code is a bit hard to read/understand.

Anyway, have happy web dev life with sbt and xsbt-web-plugin!