SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
SBT CRASH COURSEBy /Michal Bigos @teliatko
SBT CRASH COURSE
1. Why SBT
2. How SBT works
3. Example of simple project
4. Core concepts
WHY SBT
GOOD BUILD TOOL CRITERIA
Reproducibility - automating build, gives you more time to
do real stuff
Conventions - using sensible defaults, no need to specify
every last option and command
Experience - distilation of developer wisdom, e.g. test
before publish
Portability - good build tool should protect you from
differences betweeen systems
Ecosystem - allow to extend build easily
WHY SBT
LITTLE HISTORY: APACHE ANT
Former standard build tool for Java projects
Pros:
1. Portability - build is defined in XML by chaining tasks
2. Experience - abillity to explicitly define dependencies
between tasks
Cons:
1. Conventions - no default build lifecycle, each build is
piece of art
2. Ecosystem - not easy to extend, task definition
distributed as jar
WHY SBT
LITTLE HISTORY: APACHE MAVEN
Currently heavily used in enterprise Java projects
Most opinionated build tool
Pros:
1. Portability - build is defined in XML so called POM
2. Experience, Conventions - Maven introduces default
lifecycle with its phases and tasks. It promotes
declarative dependency management.
Cons:
1. Ecosystem - not easy to extend. Maven plug-in
archtecrure requires plug-in written in Java, then POMs
and packaging and availability in repository.
WHY SBT
LITTLE HISTORY: GOOD PARTS
Default project layout (Maven)
Default project behavior (Maven)
Declarative dependency management (Maven)
Portability (Ant, Maven)
WHY SBT
FEATURES AT GLACE
Uses Scala to describe build
Can be used for Java and Scala
Minimal configuration (inspired by Maven)
A number of build-in tasks
Declarative dependency management (using Apache Ivy)
Portability
Reactive development environment
Allows use Scala REPL
Incremental compilation
Automatic re-compilation with different versions of Scala
HOW SBT WORKS
TASKS
Task based, more like ANT, no phases like in Maven
If you want to do something you execute a task
If you want to ensure that a task runs after another, add an
explicit dependency between the tasks
Output of a task is value, which can be of any type and past
to any another task
Multiple tasks can depend upon the output of the same
task
By default tasks are executed in parallel
Using dependency tree sbt can work out what can be run in
parallel or in sequence
HOW SBT WORKS
DEFAULT STRUCTURE AND LAYOUT
Inspired by Maven
{project root}
project/
build.properties
plugins.sbt
src/
main/
scala/
java/
resources/
test/
scala/
java/
resources/
target/
build.sbt
HOW SBT WORKS
TASKS 'VS PLUGINS
Appear directly in build definition file, shared via VCS
Task can be turned into plugin and shared via repository
val gitHeadCommitSHA = taskKey[String]("Determines the current git comm
it SHA")
gitHeadComitSHA := Process("git rev-parse HEAD").lines.head
HOW SBT WORKS
PHASES 'VS TASK DEPENDENCIES
In Maven, the order of execution tasks in phases always
leads to confusion
Default goals for a phase are executed before explicitly
defined and those are executed in implicit order of
definition in POM file
Implicit order of execution can cause problems when
parallelizing build, if there are dependencies between goals
SBT is per default parallel, that's why explicit definition of
task dependencies is needed
It's similar to definition a custom lifecycle in Maven,
which is not easy too
HOW SBT WORKS
PARALLEL EXECUTION
If task A depends on B, and C also depends on B => SBT will
run B first and then A and C in parallel
HOW SBT WORKS
PASSING INFORMATION BETWEEN TASKS
In Maven and ANT it's very hard to pass an information
between tasks
Usually through an intermediate file
In SBT, you can simply return the value from the task and
use it in another dependent task
This makes chaining tasks a lot easier
HOW SBT WORKS
WORKING WITH SCALA
Cross compilation for multiple Scala versions => Scala is
binary compatible only between minor version releases
Not restricted to Scala versions either
scalaVersion := "2.10.1"
crossScalaVersions := Seq("2.8.2", "2.9.2")
libraryDependencies += (scalaBinaryVersion.value match {
case "2.10" => "org.specs2" %% "specs2" % "2.0"
case "2.9.1" => "org.specs2" %% "specs2" % "1.12.4"
})
HOW SBT WORKS
WORKING WITH SCALA, TAKE TWO
Scala compiler generates lots more classes and JVM takes
longer to start-up => interactive environment
Scala compilation is slow (in comparision to Java) =>
incremental compilation
Multi-module builds => parallel execution, child modules
don't need to know about parent module
EXAMPLE OF SIMPLE PROJECT
A COMMON DEVELOPERS USAGE
CORE CONCEPTS
BUILD FILES
build.properties
build.sbt
Blank line is required between settings
project/
build.properties - defines SBT version
plugins.sbt - defines SBT plugins
build.sbt - defines actual build, project settings
sbt.version = 0.12.4
name := "big-project"
version := "1.0"
scalaVersion := "2.10.0"
libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1" % "
test"
CORE CONCEPTS
SETTINGS
Mechanism to configure a build to to perform th ework we
need to
SBT reads all the settings defined in build at load time and
runs their initializations
name := "big-project"
| | |
key operator intialization
CORE CONCEPTS
SETTINGS, TAKE TWO
Settings are typesafe => every key has only one type and any
value placed into setting must match exact type
Grouping of SettingKey[T]with Initialize[T]
creates Setting[T]
name := "big-project"
| |
SettingKey[String] Initialize[String]
CORE CONCEPTS
SETTINGS, TAKE THREE
Operators used with settings
Types have to match
name := "big-project"
|
assignment
libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1"
|
append
append multiple values
|
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "1.9.1" % "test",
"org.specs2" %% "specs2" % "2.0" % "test"
)
CORE CONCEPTS
SETTINGS, TAKE FOUR
Initializations are a Scala expressions that can produce value
of desired type
Intializations may use other settings via setting.value
method.
version := "1.0"
libraryDependencies += ("org.scalatest" %% "scalatest" % version.value)
| |
SetingKey[ModuleID] Initialization[ModuleId]
 /
Setting[ModuleID]
CORE CONCEPTS
DEFINING DEPENDENCIES
Definition of exact version
Cross-compiled dependency
groupId % artifactId % version % scope
groupId %% artifactId % version % scope
|
Use appropriate scala version from project
CORE CONCEPTS
CIRCULAR REFERENCES
Because SBT can use values of one setting to instatiate
another, it's possible to create circular references
Build will fail to load when circular references are
detected.
CORE CONCEPTS
CUSTOM TASKS AND SETTINGS
For version 0.12.4 have to be defined in Scala file not sbt
one
From 0.13.0 they can be defined in sbt too
val gitHeadCommitSHA = taskKey[String]("Determines the current git
commit SHA")
|
setting/task definition
gitHeadComitSHA := Process("git rev-parse HEAD").lines.head
| |
setting/task key block of code returning value
Definitions are compiled first and can reference another
definitions
Settings are executed after definitions, hence can refence
any definition
Tasks are executed every time the value is requested
CORE CONCEPTS
CUSTOM TASKS AND SETTINGS
For version 0.12.4 have to be defined in Scala file not sbt
one
From 0.13.0 they can be defined in sbt too
val gitHeadCommitSHA = taskKey[String]("Determines the current git
commit SHA")
|
setting/task definition
gitHeadComitSHA := Process("git rev-parse HEAD").lines.head
| |
setting/task key block of code returning value
Definitions are compiled first and can reference another
definitions
Settings are executed after definitions, hence can refence
any definition
Tasks are executed every time the value is requested
MORE TO COVER
1. Scopes
2. Multi-module projects
3. Basic SBT objects in Scala
THANKS FOR YOUR ATTENTION

Weitere ähnliche Inhalte

Was ist angesagt?

Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with GradleRyan Cuprak
 
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...ZeroTurnaround
 
The world of gradle - an introduction for developers
The world of gradle  - an introduction for developersThe world of gradle  - an introduction for developers
The world of gradle - an introduction for developersTricode (part of Dept)
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Rajmahendra Hegde
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingSchalk Cronjé
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingSchalk Cronjé
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolvedBhagwat Kumar
 
Java build tool_comparison
Java build tool_comparisonJava build tool_comparison
Java build tool_comparisonManav Prasad
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeansRyan Cuprak
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with MavenSid Anand
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin WritingSchalk Cronjé
 
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleSkills Matter
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingSchalk Cronjé
 
Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)Ryan Cuprak
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache AntShih-Hsiang Lin
 
Gradle - time for another build
Gradle - time for another buildGradle - time for another build
Gradle - time for another buildIgor Khotin
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules uploadRyan Cuprak
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsGR8Conf
 

Was ist angesagt? (20)

Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
 
The world of gradle - an introduction for developers
The world of gradle  - an introduction for developersThe world of gradle  - an introduction for developers
The world of gradle - an introduction for developers
 
GradleFX
GradleFXGradleFX
GradleFX
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin Writing
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin Writing
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
 
Java build tool_comparison
Java build tool_comparisonJava build tool_comparison
Java build tool_comparison
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin Writing
 
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: Gradle
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin Writing
 
Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache Ant
 
Gradle - time for another build
Gradle - time for another buildGradle - time for another build
Gradle - time for another build
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails Projects
 

Andere mochten auch

Sbt tutorial
Sbt tutorialSbt tutorial
Sbt tutorialGary Gai
 
Road to sbt 1.0 paved with server
Road to sbt 1.0   paved with serverRoad to sbt 1.0   paved with server
Road to sbt 1.0 paved with serverEugene Yokota
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Eugene Yokota
 
Innovating faster with SBT, Continuous Delivery, and LXC
Innovating faster with SBT, Continuous Delivery, and LXCInnovating faster with SBT, Continuous Delivery, and LXC
Innovating faster with SBT, Continuous Delivery, and LXCkscaldef
 
Hadoop Summit 2013 : Continuous Integration on top of hadoop
Hadoop Summit 2013 : Continuous Integration on top of hadoopHadoop Summit 2013 : Continuous Integration on top of hadoop
Hadoop Summit 2013 : Continuous Integration on top of hadoopWisely chen
 
Continuous Integration for Spark Apps by Sean McIntyre
Continuous Integration for Spark Apps by Sean McIntyreContinuous Integration for Spark Apps by Sean McIntyre
Continuous Integration for Spark Apps by Sean McIntyreSpark Summit
 
The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)
The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)
The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)Eugene Yokota
 

Andere mochten auch (10)

SBT Made Simple
SBT Made SimpleSBT Made Simple
SBT Made Simple
 
Sbt tutorial
Sbt tutorialSbt tutorial
Sbt tutorial
 
Road to sbt 1.0 paved with server
Road to sbt 1.0   paved with serverRoad to sbt 1.0   paved with server
Road to sbt 1.0 paved with server
 
A day with sbt
A day with sbtA day with sbt
A day with sbt
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)
 
Innovating faster with SBT, Continuous Delivery, and LXC
Innovating faster with SBT, Continuous Delivery, and LXCInnovating faster with SBT, Continuous Delivery, and LXC
Innovating faster with SBT, Continuous Delivery, and LXC
 
Hadoop Summit 2013 : Continuous Integration on top of hadoop
Hadoop Summit 2013 : Continuous Integration on top of hadoopHadoop Summit 2013 : Continuous Integration on top of hadoop
Hadoop Summit 2013 : Continuous Integration on top of hadoop
 
Continuous Integration for Spark Apps by Sean McIntyre
Continuous Integration for Spark Apps by Sean McIntyreContinuous Integration for Spark Apps by Sean McIntyre
Continuous Integration for Spark Apps by Sean McIntyre
 
The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)
The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)
The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)
 
Build application using sbt
Build application using sbtBuild application using sbt
Build application using sbt
 

Ähnlich wie SBT Crash Course

How to start using Scala
How to start using ScalaHow to start using Scala
How to start using ScalaNgoc Dao
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipseMike Slinn
 
Lessons Learned: Scala and its Ecosystem
Lessons Learned: Scala and its EcosystemLessons Learned: Scala and its Ecosystem
Lessons Learned: Scala and its EcosystemPetr Hošek
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with GradleRyan Cuprak
 
Dependency injection in scala
Dependency injection in scalaDependency injection in scala
Dependency injection in scalaMichal Bigos
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topicKalkey
 
Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)Robert Scholte
 
Kubernetes for Java developers
Kubernetes for Java developersKubernetes for Java developers
Kubernetes for Java developersRobert Barr
 
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)Robert Scholte
 
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipelineKubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipelineKubeAcademy
 
Spark Streaming Info
Spark Streaming InfoSpark Streaming Info
Spark Streaming InfoDoug Chang
 
Prudential Insurance Exp
Prudential Insurance ExpPrudential Insurance Exp
Prudential Insurance ExpAnkit Chohan
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 featuresAngel Ruiz
 
Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)Robert Scholte
 

Ähnlich wie SBT Crash Course (20)

How to start using Scala
How to start using ScalaHow to start using Scala
How to start using Scala
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
 
Lessons Learned: Scala and its Ecosystem
Lessons Learned: Scala and its EcosystemLessons Learned: Scala and its Ecosystem
Lessons Learned: Scala and its Ecosystem
 
Sbt
SbtSbt
Sbt
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Dependency injection in scala
Dependency injection in scalaDependency injection in scala
Dependency injection in scala
 
Play framework
Play frameworkPlay framework
Play framework
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topic
 
Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)Apache maven and its impact on java 9 (Java One 2017)
Apache maven and its impact on java 9 (Java One 2017)
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
kishore_Nokia
kishore_Nokiakishore_Nokia
kishore_Nokia
 
Kubernetes for Java developers
Kubernetes for Java developersKubernetes for Java developers
Kubernetes for Java developers
 
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
 
Apache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI ToolboxApache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI Toolbox
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
 
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipelineKubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
 
Spark Streaming Info
Spark Streaming InfoSpark Streaming Info
Spark Streaming Info
 
Prudential Insurance Exp
Prudential Insurance ExpPrudential Insurance Exp
Prudential Insurance Exp
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
 
Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)
 

Kürzlich hochgeladen

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 

Kürzlich hochgeladen (20)

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 

SBT Crash Course

  • 1. SBT CRASH COURSEBy /Michal Bigos @teliatko
  • 2. SBT CRASH COURSE 1. Why SBT 2. How SBT works 3. Example of simple project 4. Core concepts
  • 3. WHY SBT GOOD BUILD TOOL CRITERIA Reproducibility - automating build, gives you more time to do real stuff Conventions - using sensible defaults, no need to specify every last option and command Experience - distilation of developer wisdom, e.g. test before publish Portability - good build tool should protect you from differences betweeen systems Ecosystem - allow to extend build easily
  • 4. WHY SBT LITTLE HISTORY: APACHE ANT Former standard build tool for Java projects Pros: 1. Portability - build is defined in XML by chaining tasks 2. Experience - abillity to explicitly define dependencies between tasks Cons: 1. Conventions - no default build lifecycle, each build is piece of art 2. Ecosystem - not easy to extend, task definition distributed as jar
  • 5. WHY SBT LITTLE HISTORY: APACHE MAVEN Currently heavily used in enterprise Java projects Most opinionated build tool Pros: 1. Portability - build is defined in XML so called POM 2. Experience, Conventions - Maven introduces default lifecycle with its phases and tasks. It promotes declarative dependency management. Cons: 1. Ecosystem - not easy to extend. Maven plug-in archtecrure requires plug-in written in Java, then POMs and packaging and availability in repository.
  • 6. WHY SBT LITTLE HISTORY: GOOD PARTS Default project layout (Maven) Default project behavior (Maven) Declarative dependency management (Maven) Portability (Ant, Maven)
  • 7. WHY SBT FEATURES AT GLACE Uses Scala to describe build Can be used for Java and Scala Minimal configuration (inspired by Maven) A number of build-in tasks Declarative dependency management (using Apache Ivy) Portability Reactive development environment Allows use Scala REPL Incremental compilation Automatic re-compilation with different versions of Scala
  • 8. HOW SBT WORKS TASKS Task based, more like ANT, no phases like in Maven If you want to do something you execute a task If you want to ensure that a task runs after another, add an explicit dependency between the tasks Output of a task is value, which can be of any type and past to any another task Multiple tasks can depend upon the output of the same task By default tasks are executed in parallel Using dependency tree sbt can work out what can be run in parallel or in sequence
  • 9. HOW SBT WORKS DEFAULT STRUCTURE AND LAYOUT Inspired by Maven {project root} project/ build.properties plugins.sbt src/ main/ scala/ java/ resources/ test/ scala/ java/ resources/ target/ build.sbt
  • 10. HOW SBT WORKS TASKS 'VS PLUGINS Appear directly in build definition file, shared via VCS Task can be turned into plugin and shared via repository val gitHeadCommitSHA = taskKey[String]("Determines the current git comm it SHA") gitHeadComitSHA := Process("git rev-parse HEAD").lines.head
  • 11. HOW SBT WORKS PHASES 'VS TASK DEPENDENCIES In Maven, the order of execution tasks in phases always leads to confusion Default goals for a phase are executed before explicitly defined and those are executed in implicit order of definition in POM file Implicit order of execution can cause problems when parallelizing build, if there are dependencies between goals SBT is per default parallel, that's why explicit definition of task dependencies is needed It's similar to definition a custom lifecycle in Maven, which is not easy too
  • 12. HOW SBT WORKS PARALLEL EXECUTION If task A depends on B, and C also depends on B => SBT will run B first and then A and C in parallel
  • 13. HOW SBT WORKS PASSING INFORMATION BETWEEN TASKS In Maven and ANT it's very hard to pass an information between tasks Usually through an intermediate file In SBT, you can simply return the value from the task and use it in another dependent task This makes chaining tasks a lot easier
  • 14. HOW SBT WORKS WORKING WITH SCALA Cross compilation for multiple Scala versions => Scala is binary compatible only between minor version releases Not restricted to Scala versions either scalaVersion := "2.10.1" crossScalaVersions := Seq("2.8.2", "2.9.2") libraryDependencies += (scalaBinaryVersion.value match { case "2.10" => "org.specs2" %% "specs2" % "2.0" case "2.9.1" => "org.specs2" %% "specs2" % "1.12.4" })
  • 15. HOW SBT WORKS WORKING WITH SCALA, TAKE TWO Scala compiler generates lots more classes and JVM takes longer to start-up => interactive environment Scala compilation is slow (in comparision to Java) => incremental compilation Multi-module builds => parallel execution, child modules don't need to know about parent module
  • 16. EXAMPLE OF SIMPLE PROJECT A COMMON DEVELOPERS USAGE
  • 17. CORE CONCEPTS BUILD FILES build.properties build.sbt Blank line is required between settings project/ build.properties - defines SBT version plugins.sbt - defines SBT plugins build.sbt - defines actual build, project settings sbt.version = 0.12.4 name := "big-project" version := "1.0" scalaVersion := "2.10.0" libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1" % " test"
  • 18.
  • 19. CORE CONCEPTS SETTINGS Mechanism to configure a build to to perform th ework we need to SBT reads all the settings defined in build at load time and runs their initializations name := "big-project" | | | key operator intialization
  • 20. CORE CONCEPTS SETTINGS, TAKE TWO Settings are typesafe => every key has only one type and any value placed into setting must match exact type Grouping of SettingKey[T]with Initialize[T] creates Setting[T] name := "big-project" | | SettingKey[String] Initialize[String]
  • 21. CORE CONCEPTS SETTINGS, TAKE THREE Operators used with settings Types have to match name := "big-project" | assignment libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1" | append append multiple values | libraryDependencies ++= Seq( "org.scalatest" %% "scalatest" % "1.9.1" % "test", "org.specs2" %% "specs2" % "2.0" % "test" )
  • 22. CORE CONCEPTS SETTINGS, TAKE FOUR Initializations are a Scala expressions that can produce value of desired type Intializations may use other settings via setting.value method. version := "1.0" libraryDependencies += ("org.scalatest" %% "scalatest" % version.value) | | SetingKey[ModuleID] Initialization[ModuleId] / Setting[ModuleID]
  • 23. CORE CONCEPTS DEFINING DEPENDENCIES Definition of exact version Cross-compiled dependency groupId % artifactId % version % scope groupId %% artifactId % version % scope | Use appropriate scala version from project
  • 24. CORE CONCEPTS CIRCULAR REFERENCES Because SBT can use values of one setting to instatiate another, it's possible to create circular references Build will fail to load when circular references are detected.
  • 25. CORE CONCEPTS CUSTOM TASKS AND SETTINGS For version 0.12.4 have to be defined in Scala file not sbt one From 0.13.0 they can be defined in sbt too val gitHeadCommitSHA = taskKey[String]("Determines the current git commit SHA") | setting/task definition gitHeadComitSHA := Process("git rev-parse HEAD").lines.head | | setting/task key block of code returning value
  • 26. Definitions are compiled first and can reference another definitions Settings are executed after definitions, hence can refence any definition Tasks are executed every time the value is requested
  • 27. CORE CONCEPTS CUSTOM TASKS AND SETTINGS For version 0.12.4 have to be defined in Scala file not sbt one From 0.13.0 they can be defined in sbt too val gitHeadCommitSHA = taskKey[String]("Determines the current git commit SHA") | setting/task definition gitHeadComitSHA := Process("git rev-parse HEAD").lines.head | | setting/task key block of code returning value
  • 28. Definitions are compiled first and can reference another definitions Settings are executed after definitions, hence can refence any definition Tasks are executed every time the value is requested
  • 29. MORE TO COVER 1. Scopes 2. Multi-module projects 3. Basic SBT objects in Scala
  • 30. THANKS FOR YOUR ATTENTION