SBTfor mere mortals
Whats inside?●   Where did my XML go?●   How does it work?●   Where do the files go●   Whats up with all the operators?●  ...
Where did my XML go?Short answer:awayLong answer:I hope it stays there
How does it work● Keys  ○ Names for properties: setting key  ○ Names for tasks: task key, input task key● Containers for k...
How does it work?Scopes really tie the thing together.Keys get values attached to them at scopeaxesSaying:  name := "aweso...
Where do the files go./*.sbt and project/*.scala   both belong to the same build.The ./*.sbt files provide settings for th...
Where do the files goGlobal settings for a user:~/.sbt/sbt.version/*.sbtGlobal plugins for a user:~/.sbt/sbt.version//plug...
Whats up with all the operators? :=  set a value of a property from a value +=  add a value to a key that is a list++=  ad...
Creating a projectEither use ./build.sbt directlyor create a project/build.scalaobject MyBuild extends Build {  lazy val r...
Adding dependenciesRequiring full name with version modifier:"org.json4s" % "json4s-jackson_2.10" %"3.1.0"Name only, no ve...
DependenciesExcluding items"com.amazon" % "aws-jdk" % "3.3.1" exclude("org.apache.httpcomponents", "httpclient")Intransiti...
Creating a pluginwriting an sbt plugin or a build file are thesame thing. The plugin is reusable andsharable across many p...
Creating a pluginclass Greeter(greeting: String) {  def greet(             name: String,             from: String,        ...
Creating a pluginKeys: val objKey = SettingKey[Greeter]("greeter") val taskKey = TaskKey[Unit]("greet")Settings:  objKey :...
Creating a pluginWrap those up in an object that extendsPlugin and put those settings in a Seq[Setting[_]] and youre good ...
Creating a pluginHOMEWORK:Try to create a plugin that will display thelatest tweet for a user given a user namefrom an sbt...
And now?Go forth and build awesome stuff?Youll probably want to look at the sbt.Keysfile, to see what all the keys are tha...
Upcoming SlideShare
Loading in …5
×

Sbt for mere mortals

440 views
363 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
440
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
3
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Sbt for mere mortals

  1. 1. SBTfor mere mortals
  2. 2. Whats inside?● Where did my XML go?● How does it work?● Where do the files go● Whats up with all the operators?● Creating plugins● And now?● Wordnik services
  3. 3. Where did my XML go?Short answer:awayLong answer:I hope it stays there
  4. 4. How does it work● Keys ○ Names for properties: setting key ○ Names for tasks: task key, input task key● Containers for keys: ○ projects ○ build ○ plugin● Configurations: ○ Kind of like package names in regular code in that they provide namespacing ○ Can have different classpath and dependency information
  5. 5. How does it work?Scopes really tie the thing together.Keys get values attached to them at scopeaxesSaying: name := "awesomest-project-ever"is really the same as saying name in This := "awesomest-..."the task compile refers to:compile in (Compile, This)
  6. 6. Where do the files go./*.sbt and project/*.scala both belong to the same build.The ./*.sbt files provide settings for theproject defined with base = file(".")module/something/*.sbt provides settings fora submodule defined in project/build.scalawith base = file("modules/something")
  7. 7. Where do the files goGlobal settings for a user:~/.sbt/sbt.version/*.sbtGlobal plugins for a user:~/.sbt/sbt.version//plugins/*.sbt and ~/.sbt/sbt.version//plugin/project/*.scalaPlugins local to a project:project/*.sbt and project/project/*.scala
  8. 8. Whats up with all the operators? := set a value of a property from a value += add a value to a key that is a list++= add a list of values to a key that is a list ~= update a value with a function T => T<<= set a value of a property from a sbt value<+= add a value of a property from a sbt value<++= adds a list of values like <+=
  9. 9. Creating a projectEither use ./build.sbt directlyor create a project/build.scalaobject MyBuild extends Build { lazy val root = Project( id = "friendly-name-for-project", base = file(".") // place to look for files )}
  10. 10. Adding dependenciesRequiring full name with version modifier:"org.json4s" % "json4s-jackson_2.10" %"3.1.0"Name only, no version modifier:"org.json4s" %% "json4s-jackson" % "3.1.0"
  11. 11. DependenciesExcluding items"com.amazon" % "aws-jdk" % "3.3.1" exclude("org.apache.httpcomponents", "httpclient")Intransitive"com.mongodb" %% "casbah" % "2.5.0" instransitive()Classifier"com.mongodb" %% "casbah" % "2.5.0" classifier("wordnik")
  12. 12. Creating a pluginwriting an sbt plugin or a build file are thesame thing. The plugin is reusable andsharable across many projects. Other thanthat they are the same.If you can write it in a class you can write it insbt, its a matter of seeing the translation andbreaking it apart in context + behavior, likemost other things Scala.
  13. 13. Creating a pluginclass Greeter(greeting: String) { def greet( name: String, from: String, log: String => Unit) = log( greeting + " " + name + " from " + from)}
  14. 14. Creating a pluginKeys: val objKey = SettingKey[Greeter]("greeter") val taskKey = TaskKey[Unit]("greet")Settings: objKey := new Greeter("Hello") name in taskKey := "Ivan" taskKey <<= (name in taskKey, name, objKey,streams) {(theName, from, obj, s) => obj.greet(theName, from, s.log.info(_) }
  15. 15. Creating a pluginWrap those up in an object that extendsPlugin and put those settings in a Seq[Setting[_]] and youre good to go, youve gota plugin.
  16. 16. Creating a pluginHOMEWORK:Try to create a plugin that will display thelatest tweet for a user given a user namefrom an sbt setting.or instead of a tweet, try downloading the listof open issues from jira when credentials areprovided.
  17. 17. And now?Go forth and build awesome stuff?Youll probably want to look at the sbt.Keysfile, to see what all the keys are that arecurrently defined.Read the source of many other plugins, sothat they no longer appear to do magic.

×