SlideShare a Scribd company logo
SBT Concepts
Happy Monday @ Gilt
     Feb 2013

  rtritsch@gilt.com
Playing with/Debugging SBT
● > settings -V <regex>
● > tasks -V <regex>
● > inspect <setting/task>
  ○ good to get the type of a setting/task
  ○ inspect tree <setting/task>
● > show <setting/task>
● > project <project>
● > ~reload


● Keys.scala
Basics
● An SBT build is an immutable map of key-
  value pairs describing the build
   ○ e.g. version = "0.0.1"
● When loading the *.sbt and *.scala files SBT
  builds a (long, huge) list of Setting[T] objects
  that describe a transformation to the map
   ○ e.g. name := "My Project"
● The list is then first sorted and the each
  Setting[T] is applied to the map
Basics (cont.)
● A Setting[T] can be build/expressed as ...
  ○ Key := Value where Key is one of ...
    ■ SettingKey[T], TaskKey[T], InputKey[T]
● There are lots of predefined Keys
  ○ Look at Keys.scala
● The operator describes the transformation
  ○ e.g. := replaces a key-value with another one, +=
    would add a value to a list
    ■ e.g. given an existing Setting[List[String]]
       identified by a SettingKey[List[String]] called
       example, you can add a value to the setting
       with ...
         ●   example += "another string"
Basics - Keys
● SettingKey[T] are computed once when the
  project is loaded and kept around
● TaskKey[T] are computed every time they
  are evaluated
  ○ val showTime = TaskKey[Unit]("show-time", "...")
  ○ showTime := {println <Time>}
  ○ This will result in a Setting[Task[Unit]] that can be
    added to the list of settings
● InputKey[T] to be discussed later
Basics - Scopes
● Actually ...
   ○ ... there is not one Key, but lots of them, because ...
   ○ ... they are Scoped, means ...
   ○ ... e.g. name can have a different value in different
     scopes
● Scopes have 3 axis: Project, Configuration
  and Task
   ○ Project should be clear/obvious
   ○ Configurations are e.g. Compile, Test, RunTime
   ○ Tasks are e.g. package-bin, package-src
     ■ scoping is used to give SettingKeys a different
        value for a task (e.g. artifactName)
Basics - Scopes (cont.)
● Special scopes are ...
  ○ There is a global scope for Configuration and Tasks
    called "Global"
    ■ <key> in (Global, Global) := ...
  ○ There is an "entire-build" scope called "ThisBuild"
    ■ <key> in ThisBuild := ...
        ●   same as <key> := ...
● Project scoping happens by putting the setting
  into the right scope (as opposed to using the
  "in" operator)
● Last but not least ... <key> in (Compile,
  compile) := ... make total sense, right?
Basic - Scopes (cont.)
● Use inspect to explore scoping
  ○ Learn how to read Provided-by, Delegates and
    Related
● Use show to display (Task)Keys
● Make inspect tree <key> work
Setting settings :)
●   (Re)Set - := [T]
●   Append value (to Seq) - += [T]
●   Append seq (to Seq) - ++= Seq[T]
●   Apply function to previous value(s) - ~= {T=>T}
●   Make a setting depend on another - <<=
SBT builds are SBT projects :)
● Look at ../project/project/Build.scala
   ○ Every project loads all *.sbt files from the root plus
     all *.scala files from the project/ directory
   ○ Explore the difference between version.sbt and
     plugins.sbt
Wrap up ...
             ... continue to play on ...
https://github.com/rolandtritsch/scala-sbt-tutorial
Backup
Using sbt-assembly ... right
● Initially it "just" adds a new task: assembly
● Question is ... how does this task relate and
  integrate with the rest of the build process, e.
  g. package and publish?
● Conceptually ... you first compile, then you
  package and then you publish
   ○ Package has multiple sub-tasks (package-bin,
     package-src, package-doc)
   ○ Each sub-task produces an Artifact that can then get
     published
Using sbt-assembly ... right (cont.)
● Proposal is ...
   ○ ... to introduce a new task package-assembly
   ○ ... and to run this task when package runs
   ○ ... and have it produce a new Artifact
   ○ ... and publish this Artifact as part of the publish task
     (or the publish-to or the publish-local) and a name
     that is different from the name that is used to
     package/publish the bin)
   ○ ... and make that work as part of the Compile
     configuration (should not be available in the Test
     configuration)
   ○ ... and get rid of running the tests as part of
     packaging it
Using sbt-assembly ... right (cont.)
● sbt <project> compile
● sbt <project> package
● sbt <project> publish

● sbt <project> package-assembly
● sbt <project> publish-local
● sbt <project> publish-to
Work in progress
Multi-Project Builds
● aggregate vs. dependsOn
Compile, package and publish ...
● What you publish is an Artifact
Advanced
● InputKey[T] ...

More Related Content

PPTX
SBT Concepts, part 2
PDF
SBT Crash Course
PDF
Simple Build Tool
PPT
An introduction to maven gradle and sbt
PDF
Continous delivery with sbt
PDF
Custom deployments with sbt-native-packager
PDF
Ship your Scala code often and easy with Docker
PDF
Idiomatic Gradle Plugin Writing
SBT Concepts, part 2
SBT Crash Course
Simple Build Tool
An introduction to maven gradle and sbt
Continous delivery with sbt
Custom deployments with sbt-native-packager
Ship your Scala code often and easy with Docker
Idiomatic Gradle Plugin Writing

What's hot (20)

PPTX
PDF
Idiomatic Gradle Plugin Writing
PDF
Idiomatic Gradle Plugin Writing
PPT
Simple build tool
PDF
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
PDF
10 Cool Facts about Gradle
PDF
Basic Gradle Plugin Writing
PDF
Developing your own OpenStack Swift middleware
PDF
Http4s, Doobie and Circe: The Functional Web Stack
PDF
DevOps Odessa #TechTalks 21.01.2020
PPTX
Jenkins' shared libraries in action
PPT
PDF
Gradle Introduction
PDF
Gradle in 45min
PPT
PDF
Idiomatic gradle plugin writing
PDF
In the Brain of Hans Dockter: Gradle
PPT
Intro to-ant
PPTX
Prometheus: infrastructure and application monitoring in kubernetes cluster
PDF
Gradle talk, Javarsovia 2010
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin Writing
Simple build tool
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
10 Cool Facts about Gradle
Basic Gradle Plugin Writing
Developing your own OpenStack Swift middleware
Http4s, Doobie and Circe: The Functional Web Stack
DevOps Odessa #TechTalks 21.01.2020
Jenkins' shared libraries in action
Gradle Introduction
Gradle in 45min
Idiomatic gradle plugin writing
In the Brain of Hans Dockter: Gradle
Intro to-ant
Prometheus: infrastructure and application monitoring in kubernetes cluster
Gradle talk, Javarsovia 2010
Ad

Similar to Sbt Concepts - Tips, Tricks, Sandbox, ... 02/2013 (20)

PDF
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
PPT
This is a python. Ppt it is used for bca student also.
PDF
The Ring programming language version 1.9 book - Part 90 of 210
PDF
Qt for beginners part 2 widgets
 
PPTX
Deep dive - Concourse CI/CD and Pipelines
PPTX
C++ STL (quickest way to learn, even for absolute beginners).pptx
PPTX
C++ STL (quickest way to learn, even for absolute beginners).pptx
PDF
The Ring programming language version 1.6 book - Part 16 of 189
ODP
Talk on Standard Template Library
PDF
The Ring programming language version 1.7 book - Part 17 of 196
PDF
The Ring programming language version 1.5.2 book - Part 21 of 181
PDF
Apache Flink Training Workshop @ HadoopCon2016 - #2 DataSet API Hands-On
PPTX
constructocvbcvbcvbcvbr-Destructor (1).pptx
PPT
Constructor,destructors cpp
PDF
CMake_Tutorial.pdf
PDF
R programming for data science
PDF
Meetup C++ A brief overview of c++17
PPTX
AI02_Python (cont.).pptx
PPT
classes and constructors lec 03 & 04.ppt
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
This is a python. Ppt it is used for bca student also.
The Ring programming language version 1.9 book - Part 90 of 210
Qt for beginners part 2 widgets
 
Deep dive - Concourse CI/CD and Pipelines
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
The Ring programming language version 1.6 book - Part 16 of 189
Talk on Standard Template Library
The Ring programming language version 1.7 book - Part 17 of 196
The Ring programming language version 1.5.2 book - Part 21 of 181
Apache Flink Training Workshop @ HadoopCon2016 - #2 DataSet API Hands-On
constructocvbcvbcvbcvbr-Destructor (1).pptx
Constructor,destructors cpp
CMake_Tutorial.pdf
R programming for data science
Meetup C++ A brief overview of c++17
AI02_Python (cont.).pptx
classes and constructors lec 03 & 04.ppt
Ad

More from Roland Tritsch (14)

PPTX
Shared-Nothing Microservices Architectures ... and how to get there @ 404.ie ...
PDF
SMACK Stack @ Nitro
PDF
Reactive Programming Meetup - NodeJs on K8s
PDF
Scala, Android & BLE - Scala Meetup Dublin - Hands on code walkthrough
PDF
Immutable Deployment Platforms and Continuos Delivery - Friends or Foes?
PDF
Mobile Monday - WebServices on the iPhone - 05/2008
PDF
A SOA for the car - 01/2009
PDF
Puppet Camp Dublin - 06/2012
PDF
iPhone meets SOA - 06/2008
PDF
Innovation, Gilt and Ireland - 11/2011
PDF
Teaching Functional Programming @ TCD - 11/2012
PDF
"Managed Customization” in the Garment Industry - 10/2010
PDF
RESTful Services and Distributed OSGi - 04/2009
PDF
AJAX for Mobile Devices - 04/2009
Shared-Nothing Microservices Architectures ... and how to get there @ 404.ie ...
SMACK Stack @ Nitro
Reactive Programming Meetup - NodeJs on K8s
Scala, Android & BLE - Scala Meetup Dublin - Hands on code walkthrough
Immutable Deployment Platforms and Continuos Delivery - Friends or Foes?
Mobile Monday - WebServices on the iPhone - 05/2008
A SOA for the car - 01/2009
Puppet Camp Dublin - 06/2012
iPhone meets SOA - 06/2008
Innovation, Gilt and Ireland - 11/2011
Teaching Functional Programming @ TCD - 11/2012
"Managed Customization” in the Garment Industry - 10/2010
RESTful Services and Distributed OSGi - 04/2009
AJAX for Mobile Devices - 04/2009

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Mushroom cultivation and it's methods.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Teaching material agriculture food technology
Network Security Unit 5.pdf for BCA BBA.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
OMC Textile Division Presentation 2021.pptx
Mushroom cultivation and it's methods.pdf
Empathic Computing: Creating Shared Understanding
SOPHOS-XG Firewall Administrator PPT.pptx
A comparative analysis of optical character recognition models for extracting...
Per capita expenditure prediction using model stacking based on satellite ima...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectroscopy.pptx food analysis technology
Group 1 Presentation -Planning and Decision Making .pptx
A comparative study of natural language inference in Swahili using monolingua...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction
TLE Review Electricity (Electricity).pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

Sbt Concepts - Tips, Tricks, Sandbox, ... 02/2013

  • 1. SBT Concepts Happy Monday @ Gilt Feb 2013 rtritsch@gilt.com
  • 2. Playing with/Debugging SBT ● > settings -V <regex> ● > tasks -V <regex> ● > inspect <setting/task> ○ good to get the type of a setting/task ○ inspect tree <setting/task> ● > show <setting/task> ● > project <project> ● > ~reload ● Keys.scala
  • 3. Basics ● An SBT build is an immutable map of key- value pairs describing the build ○ e.g. version = "0.0.1" ● When loading the *.sbt and *.scala files SBT builds a (long, huge) list of Setting[T] objects that describe a transformation to the map ○ e.g. name := "My Project" ● The list is then first sorted and the each Setting[T] is applied to the map
  • 4. Basics (cont.) ● A Setting[T] can be build/expressed as ... ○ Key := Value where Key is one of ... ■ SettingKey[T], TaskKey[T], InputKey[T] ● There are lots of predefined Keys ○ Look at Keys.scala ● The operator describes the transformation ○ e.g. := replaces a key-value with another one, += would add a value to a list ■ e.g. given an existing Setting[List[String]] identified by a SettingKey[List[String]] called example, you can add a value to the setting with ... ● example += "another string"
  • 5. Basics - Keys ● SettingKey[T] are computed once when the project is loaded and kept around ● TaskKey[T] are computed every time they are evaluated ○ val showTime = TaskKey[Unit]("show-time", "...") ○ showTime := {println <Time>} ○ This will result in a Setting[Task[Unit]] that can be added to the list of settings ● InputKey[T] to be discussed later
  • 6. Basics - Scopes ● Actually ... ○ ... there is not one Key, but lots of them, because ... ○ ... they are Scoped, means ... ○ ... e.g. name can have a different value in different scopes ● Scopes have 3 axis: Project, Configuration and Task ○ Project should be clear/obvious ○ Configurations are e.g. Compile, Test, RunTime ○ Tasks are e.g. package-bin, package-src ■ scoping is used to give SettingKeys a different value for a task (e.g. artifactName)
  • 7. Basics - Scopes (cont.) ● Special scopes are ... ○ There is a global scope for Configuration and Tasks called "Global" ■ <key> in (Global, Global) := ... ○ There is an "entire-build" scope called "ThisBuild" ■ <key> in ThisBuild := ... ● same as <key> := ... ● Project scoping happens by putting the setting into the right scope (as opposed to using the "in" operator) ● Last but not least ... <key> in (Compile, compile) := ... make total sense, right?
  • 8. Basic - Scopes (cont.) ● Use inspect to explore scoping ○ Learn how to read Provided-by, Delegates and Related ● Use show to display (Task)Keys ● Make inspect tree <key> work
  • 9. Setting settings :) ● (Re)Set - := [T] ● Append value (to Seq) - += [T] ● Append seq (to Seq) - ++= Seq[T] ● Apply function to previous value(s) - ~= {T=>T} ● Make a setting depend on another - <<=
  • 10. SBT builds are SBT projects :) ● Look at ../project/project/Build.scala ○ Every project loads all *.sbt files from the root plus all *.scala files from the project/ directory ○ Explore the difference between version.sbt and plugins.sbt
  • 11. Wrap up ... ... continue to play on ... https://github.com/rolandtritsch/scala-sbt-tutorial
  • 13. Using sbt-assembly ... right ● Initially it "just" adds a new task: assembly ● Question is ... how does this task relate and integrate with the rest of the build process, e. g. package and publish? ● Conceptually ... you first compile, then you package and then you publish ○ Package has multiple sub-tasks (package-bin, package-src, package-doc) ○ Each sub-task produces an Artifact that can then get published
  • 14. Using sbt-assembly ... right (cont.) ● Proposal is ... ○ ... to introduce a new task package-assembly ○ ... and to run this task when package runs ○ ... and have it produce a new Artifact ○ ... and publish this Artifact as part of the publish task (or the publish-to or the publish-local) and a name that is different from the name that is used to package/publish the bin) ○ ... and make that work as part of the Compile configuration (should not be available in the Test configuration) ○ ... and get rid of running the tests as part of packaging it
  • 15. Using sbt-assembly ... right (cont.) ● sbt <project> compile ● sbt <project> package ● sbt <project> publish ● sbt <project> package-assembly ● sbt <project> publish-local ● sbt <project> publish-to
  • 18. Compile, package and publish ... ● What you publish is an Artifact