SlideShare a Scribd company logo
1 of 22
SBT Concepts, part 2
Renat Bekbolatov @R2D7 - Eastside Scala Meetup - Apr 2015
Installation
• Pre-reqs: java and scala installed
• http://www.scala-sbt.org/release/tutorial/Setup.html
• sbt runs as a java program: sbt-launch.jar
2
Let’s create an SBT project
• mkdir my_project
• cd my_project
• mkdir -p project src/{main,test}/{scala,java,resources}
• echo “sbt.version=0.13.7” > project/build.properties
3
Directory Structure
• “src” contains source and resource
files
• “project” directory contains build
code for this project
• “build.properties” is a key-value
properties file for sbt
• “build.sbt” also contains build
information for this project
• “target” directory (not shown)
contains build products
Image source: http://just-thor.com/2013/11/getting-started-with-a-simple-sbt-project/
build.sbt
——————— build.sbt —————————————————————
—————————
name := "MyProj"
version := "1.0"
scalaVersion := “2.11.6”
libraryDependencies += "com.google.guava" % "guava" % "18.0"
—————————————————————————————————
———————————————
Remember from part 1, we are setting values to keys:
KEY := VALUE <——- SETTING
KEY[T] := VALUE <——- SETTING[T] - type of value
5
sbt REPL
% sbt
[info] Loading project definition from my_project/project
[info] Updating {file: my_project/project/}my_project-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to MyProj (in build file:my_project/)
(Now we are in sbt REPL)
> name
[info] MyProj
> version
[info] 1.0
>
6
show & inspect
> show name
[info] MyProj
>
> inspect name
[info] Setting: java.lang.String = MyProj <— Type and Value
[info] Description:
[info] Project name.
[info] Provided by:
[info] {file: my_project/}my_project/*:name
[info] Defined at:
[info] my_project/build.sbt:1 <——— Key “name” that
[info] Reverse dependencies: we set in build.sbt
[info] *:projectInfo
[info] *:normalizedName
[info] *:onLoadMessage
[info] *:description
[info] Delegates: <——— Delegates (more on this later)
[info] *:name
[info] {.}/*:name
[info] */*:name
>
7
src/main/scala/StringSplit.scala
————————————————————————————————-
StringSplit.sbt ———————————
package example
import com.google.common.base.Splitter
import scala.collection.JavaConversions._
object StringSplit extends App {
println("hello")
val parts = Splitter.on(',')
.trimResults()
.omitEmptyStrings()
.split("foo,bar,, baz")
parts.foreach { part => println(s"Part: $part")}
}
————————————————————————————————————
————————————————-———————8
compile & run
% sbt
[info] Loading project definition from my_project/project
[info] Set current project to MyProj (in build file:my_project/)
> compile
[info] Updating {file:my_project/}my_project...
[info] [SUCCESSFUL ] com.google.guava#guava;18.0!guava.jar(bundle) (28ms)
[info] Done updating.
[info] Compiling 1 Scala source to my_project/target/scala-2.11/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.11.6. Compiling...
[info] Compilation completed in 12.713 s
[success] Total time: 48 s, completed Apr 1, 2015 2:41:55 PM
> run
[info] Updating {file:my_project/}my_project...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 1 Scala source to my_project/target/scala-2.11/classes...
[info] Running example.StringSplit
hello
Part: foo
Part: bar
Part: baz
[success] Total time: 5 s, completed Apr 1, 2015 3:04:05 PM
>
9
package
> package
[info] Compiling 1 Scala source to my_project/target/scala-2.11/classes...
[info] Packaging my_project/target/scala-2.11/myproj_2.11-1.0.jar ...
[info] Done packaging.
[success] Total time: 1 s, completed Apr 1, 2015 3:21:59 PM
> exit
(Now we are in shell)
% ls -lh target/scala-2.11
drwxr-xr-x 3 renat renat 102B Apr 1 15:21 classes
-rw-r--r-- 1 renat renat 4.2K Apr 1 15:21 myproj_2.11-1.0.jar
10
List available tasks
(Now we are in sbt REPL)
> tasks
This is a list of tasks defined for the current project.
It does not list the scopes the tasks are defined in; use the 'inspect' command for that.
Tasks produce values. Use the 'show' command to run the task and print the resulting value.
clean Deletes files produced by the build, such as generated sources, comp…
compile Compiles sources.
console Starts the Scala interpreter with the project classes on the classpath.
… [truncated]
11
console
> console
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.11.6 (Java HotSpot(TM)
64-Bit Server VM, Java 1.7.0_60).
Type in expressions to have them evaluated.
Type :help for more information.
(Now we are in Scala console - with main classpath)
scala> import com.google.common.base.Splitter
import com.google.common.base.Splitter
scala> Splitter.on(' ').split("one two three”)
res0: Iterable[String] = [one, two, three]
scala> example.StringSplit.main(Array[String]())
hello
Part: foo
Part: bar
Part: baz
12
More on sbt commands…
• Can issue command directly in shell: “sbt run”
• Can combine commands: “sbt test package”
• clean, publish, publish-local, update, reload
• Plugins can add new keys
13
Build script
So far we have been running only with one file
build.sbt in project’s root directory.
Behind the scenes, sbt created a Project object
and appended the contents of project’s
build.sbt to its settings.
Manually creating a project by creating a Scala
file in project directory…
Build script
——————— project/MyBuild.scala ———————————————————————————
import sbt._
import sbt.Keys._
object MyBuild extends Build {
lazy val root = (project in file("."))
.settings(
name := "MyProj",
version := "1.0",
scalaVersion := "2.11.6",
libraryDependencies += "com.google.guava" % "guava" % "18.0"
)
}
—————————————————————————————————————————————————
—————————————
Same definition as before with build.sbt file.
Settings in build.sbt will be applied on top of this.
In fact, any .sbt files in a project, will be merged with the build definition for the entire build, but scoped to that
project.
15
Scopeslazy val commonSettings = Seq(
organization := "com.example",
version := "0.1.0",
scalaVersion := "2.11.4"
)
lazy val core = (project in file("core"))
.dependsOn(util)
.settings(commonSettings: _*)
.settings(
name := "projCore"
// other settings
)
lazy val util = (project in file("util"))
.settings(commonSettings: _*)
.settings(
name := "projUtil"
// other settings
)
Then in sbt:
> util/name
[info] projUtil
> core/name <— {<build-uri>}<project-id>/config:inkey::key
[info] projCore
> util/name
[info] projUtil
>
16
Configurations
A configuration defines a flavor of build, potentially with its own classpath, sources, generated
packages, etc.
The configuration concept comes from Ivy, which sbt uses for managed dependencies Library
Dependencies, and from MavenScopes.
Some configurations you’ll see in sbt:
Compile which defines the main build (src/main/scala).
Test which defines how to build tests (src/test/scala).
Runtime which defines the classpath for the run task.
By default, all the keys associated with compiling, packaging, and running are scoped to a
configuration and therefore may work differently in each configuration.
The most obvious examples are the task keys compile, package, and run; but all the keys
which affect those keys (such as sourceDirectories or scalacOptions or fullClasspath) are
also scoped to the configuration.
17
Source: http://www.scala-sbt.org/0.13/tutorial/Scopes.html
Scopes again
In build definition:
scalacOptions in Test ++= Seq(“-unchecked")
In REPL:
Test:scalacOptions
General for in REPL is {<build-uri>}<project-id>/config:intask::key
18
Plugins
A plugin extends the build definition, most commonly by adding new settings, possibly new tasks.
For example - if you want to create fat jars, there is a plugin for that: plugin “sbt-assembly”.
In project directory create file “assembly.sbt” with the following:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % “0.11.2”)
This particular plugin brings in new keys, such as:
assembly, assemblyJarName, assemblyMergeStrategy, …
Now in sbt, you can run “assembly”:
> assembly
[info] Including: guava-18.0.jar
[info] Including: scala-library-2.11.6.jar
[info] Checking every *.class/*.jar file's SHA-1.
[info] Merging files...
[warn] Merging 'META-INF/MANIFEST.MF' with strategy 'discard'
[warn] Merging 'META-INF/maven/com.google.guava/guava/pom.properties' with strategy 'discard'
[warn] Merging 'META-INF/maven/com.google.guava/guava/pom.xml' with strategy 'discard'
[warn] Strategy 'discard' was applied to 3 files
[info] SHA-1: db72fdf182c7c5332a145aa4c018466840f9c554
[info] Packaging /Users/renatb/tmp/sm/my_project/target/scala-2.11/MyProj-assembly-1.0.jar ...
[info] Done packaging.
[success] Total time: 5 s, completed Apr 1, 2015 11:51:57 PM
>
19
Delegates
A setting has a key and a scope.
A request for a key in a scope A may be delegated to another scope if A doesn't define a
value for the key.
The delegation chain is well-defined and is displayed in the Delegates section of the inspect
command.
The Delegates section shows the order in which scopes are searched when a value is not
defined for the requested key.
> inspect console::initialCommands
...
[info] Delegates:
[info] *:console::initialCommands
[info] *:initialCommands
[info] {.}/*:console::initialCommands
[info] {.}/*:initialCommands
[info] */*:console::initialCommands
[info] */*:initialCommands
...
20
Useful links
• http://www.scala-sbt.org/0.13/tutorial/index.html
• http://just-thor.com/2013/11/getting-started-with-a-
simple-sbt-project/
• http://www.scala-sbt.org/0.13/tutorial/Full-Def.html
• http://www.scala-sbt.org/0.13.2/docs/Detailed-
Topics/Inspecting-Settings.html
21
Upcoming Meetups
Seattle Spark Meetup
Sparkly Notebook: Interactive Analysis and Visualization with Spark
Wednesday, April 15, 2015 - Avvo - 705 5th Ave South #600, Seattle, WA
Scala at the Sea
Discuss Scala Akka and Related Technologies
Tuesday, April 14, 2015 - Whitepages - 1301 5th Avenue #1600, Seattle, WA
22

More Related Content

What's hot

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é
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingSchalk Cronjé
 
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
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin WritingSchalk Cronjé
 
10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about GradleEvgeny Goldin
 
Idiomatic gradle plugin writing
Idiomatic gradle plugin writingIdiomatic gradle plugin writing
Idiomatic gradle plugin writingSchalk Cronjé
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Tomek Kaczanowski
 
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
 
Continuous Integration and DevOps with Open Build Service(OBS)
Continuous Integration and DevOps with Open Build Service(OBS)Continuous Integration and DevOps with Open Build Service(OBS)
Continuous Integration and DevOps with Open Build Service(OBS)Ralf Dannert
 
State of the Jenkins Automation
State of the Jenkins AutomationState of the Jenkins Automation
State of the Jenkins AutomationJulien Pivotto
 
Prometheus: infrastructure and application monitoring in kubernetes cluster
Prometheus: infrastructure and application monitoring in kubernetes clusterPrometheus: infrastructure and application monitoring in kubernetes cluster
Prometheus: infrastructure and application monitoring in kubernetes clusterLohika_Odessa_TechTalks
 
OpenStack DevStack Tutorial
OpenStack DevStack TutorialOpenStack DevStack Tutorial
OpenStack DevStack TutorialSaju Madhavan
 

What's hot (20)

Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin Writing
 
GradleFX
GradleFXGradleFX
GradleFX
 
Simple build tool
Simple build toolSimple build tool
Simple build tool
 
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 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
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin Writing
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
3 Git
3 Git3 Git
3 Git
 
Gradle in 45min
Gradle in 45minGradle in 45min
Gradle in 45min
 
10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about Gradle
 
Idiomatic gradle plugin writing
Idiomatic gradle plugin writingIdiomatic gradle plugin writing
Idiomatic gradle plugin writing
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010
 
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
 
Jenkins' shared libraries in action
Jenkins' shared libraries in actionJenkins' shared libraries in action
Jenkins' shared libraries in action
 
DevOps Odessa #TechTalks 21.01.2020
DevOps Odessa #TechTalks 21.01.2020DevOps Odessa #TechTalks 21.01.2020
DevOps Odessa #TechTalks 21.01.2020
 
Continuous Integration and DevOps with Open Build Service(OBS)
Continuous Integration and DevOps with Open Build Service(OBS)Continuous Integration and DevOps with Open Build Service(OBS)
Continuous Integration and DevOps with Open Build Service(OBS)
 
State of the Jenkins Automation
State of the Jenkins AutomationState of the Jenkins Automation
State of the Jenkins Automation
 
Prometheus: infrastructure and application monitoring in kubernetes cluster
Prometheus: infrastructure and application monitoring in kubernetes clusterPrometheus: infrastructure and application monitoring in kubernetes cluster
Prometheus: infrastructure and application monitoring in kubernetes cluster
 
OpenStack DevStack Tutorial
OpenStack DevStack TutorialOpenStack DevStack Tutorial
OpenStack DevStack Tutorial
 

Similar to SBT Concepts, part 2

Sbt職人のススメ
Sbt職人のススメSbt職人のススメ
Sbt職人のススメ潤一 加藤
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using ScalaNgoc Dao
 
Boost your productivity with Scala tooling!
Boost your productivity  with Scala tooling!Boost your productivity  with Scala tooling!
Boost your productivity with Scala tooling!MeriamLachkar1
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache AntShih-Hsiang Lin
 
Ordina Accelerator program 2019 - Maven
Ordina Accelerator program 2019 - MavenOrdina Accelerator program 2019 - Maven
Ordina Accelerator program 2019 - MavenBert Koorengevel
 
初心者Scala in f@n 第五回 sbt+giter8
初心者Scala in f@n 第五回 sbt+giter8初心者Scala in f@n 第五回 sbt+giter8
初心者Scala in f@n 第五回 sbt+giter8gak2223
 
SBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaSBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaVasil Remeniuk
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with GradleRyan Cuprak
 
Scala laboratory. Globus. iteration #1
Scala laboratory. Globus. iteration #1Scala laboratory. Globus. iteration #1
Scala laboratory. Globus. iteration #1Vasil Remeniuk
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Ryan Cuprak
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with GradleRyan Cuprak
 
Releasing and deploying python tools
Releasing and deploying python toolsReleasing and deploying python tools
Releasing and deploying python toolsQuintagroup
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipseMike Slinn
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to MavenSperasoft
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012alexismidon
 

Similar to SBT Concepts, part 2 (20)

Pragmatic sbt
Pragmatic sbtPragmatic sbt
Pragmatic sbt
 
Sbt職人のススメ
Sbt職人のススメSbt職人のススメ
Sbt職人のススメ
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using Scala
 
Boost your productivity with Scala tooling!
Boost your productivity  with Scala tooling!Boost your productivity  with Scala tooling!
Boost your productivity with Scala tooling!
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache Ant
 
Ordina Accelerator program 2019 - Maven
Ordina Accelerator program 2019 - MavenOrdina Accelerator program 2019 - Maven
Ordina Accelerator program 2019 - Maven
 
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
 
初心者Scala in f@n 第五回 sbt+giter8
初心者Scala in f@n 第五回 sbt+giter8初心者Scala in f@n 第五回 sbt+giter8
初心者Scala in f@n 第五回 sbt+giter8
 
SBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaSBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius Valatka
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Scala laboratory. Globus. iteration #1
Scala laboratory. Globus. iteration #1Scala laboratory. Globus. iteration #1
Scala laboratory. Globus. iteration #1
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Releasing and deploying python tools
Releasing and deploying python toolsReleasing and deploying python tools
Releasing and deploying python tools
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
OpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with GradleOpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with Gradle
 
Gradle
GradleGradle
Gradle
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012
 

Recently uploaded

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 

Recently uploaded (20)

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 

SBT Concepts, part 2

  • 1. SBT Concepts, part 2 Renat Bekbolatov @R2D7 - Eastside Scala Meetup - Apr 2015
  • 2. Installation • Pre-reqs: java and scala installed • http://www.scala-sbt.org/release/tutorial/Setup.html • sbt runs as a java program: sbt-launch.jar 2
  • 3. Let’s create an SBT project • mkdir my_project • cd my_project • mkdir -p project src/{main,test}/{scala,java,resources} • echo “sbt.version=0.13.7” > project/build.properties 3
  • 4. Directory Structure • “src” contains source and resource files • “project” directory contains build code for this project • “build.properties” is a key-value properties file for sbt • “build.sbt” also contains build information for this project • “target” directory (not shown) contains build products Image source: http://just-thor.com/2013/11/getting-started-with-a-simple-sbt-project/
  • 5. build.sbt ——————— build.sbt ————————————————————— ————————— name := "MyProj" version := "1.0" scalaVersion := “2.11.6” libraryDependencies += "com.google.guava" % "guava" % "18.0" ————————————————————————————————— ——————————————— Remember from part 1, we are setting values to keys: KEY := VALUE <——- SETTING KEY[T] := VALUE <——- SETTING[T] - type of value 5
  • 6. sbt REPL % sbt [info] Loading project definition from my_project/project [info] Updating {file: my_project/project/}my_project-build... [info] Resolving org.fusesource.jansi#jansi;1.4 ... [info] Done updating. [info] Set current project to MyProj (in build file:my_project/) (Now we are in sbt REPL) > name [info] MyProj > version [info] 1.0 > 6
  • 7. show & inspect > show name [info] MyProj > > inspect name [info] Setting: java.lang.String = MyProj <— Type and Value [info] Description: [info] Project name. [info] Provided by: [info] {file: my_project/}my_project/*:name [info] Defined at: [info] my_project/build.sbt:1 <——— Key “name” that [info] Reverse dependencies: we set in build.sbt [info] *:projectInfo [info] *:normalizedName [info] *:onLoadMessage [info] *:description [info] Delegates: <——— Delegates (more on this later) [info] *:name [info] {.}/*:name [info] */*:name > 7
  • 8. src/main/scala/StringSplit.scala ————————————————————————————————- StringSplit.sbt ——————————— package example import com.google.common.base.Splitter import scala.collection.JavaConversions._ object StringSplit extends App { println("hello") val parts = Splitter.on(',') .trimResults() .omitEmptyStrings() .split("foo,bar,, baz") parts.foreach { part => println(s"Part: $part")} } ———————————————————————————————————— ————————————————-———————8
  • 9. compile & run % sbt [info] Loading project definition from my_project/project [info] Set current project to MyProj (in build file:my_project/) > compile [info] Updating {file:my_project/}my_project... [info] [SUCCESSFUL ] com.google.guava#guava;18.0!guava.jar(bundle) (28ms) [info] Done updating. [info] Compiling 1 Scala source to my_project/target/scala-2.11/classes... [info] 'compiler-interface' not yet compiled for Scala 2.11.6. Compiling... [info] Compilation completed in 12.713 s [success] Total time: 48 s, completed Apr 1, 2015 2:41:55 PM > run [info] Updating {file:my_project/}my_project... [info] Resolving jline#jline;2.12.1 ... [info] Done updating. [info] Compiling 1 Scala source to my_project/target/scala-2.11/classes... [info] Running example.StringSplit hello Part: foo Part: bar Part: baz [success] Total time: 5 s, completed Apr 1, 2015 3:04:05 PM > 9
  • 10. package > package [info] Compiling 1 Scala source to my_project/target/scala-2.11/classes... [info] Packaging my_project/target/scala-2.11/myproj_2.11-1.0.jar ... [info] Done packaging. [success] Total time: 1 s, completed Apr 1, 2015 3:21:59 PM > exit (Now we are in shell) % ls -lh target/scala-2.11 drwxr-xr-x 3 renat renat 102B Apr 1 15:21 classes -rw-r--r-- 1 renat renat 4.2K Apr 1 15:21 myproj_2.11-1.0.jar 10
  • 11. List available tasks (Now we are in sbt REPL) > tasks This is a list of tasks defined for the current project. It does not list the scopes the tasks are defined in; use the 'inspect' command for that. Tasks produce values. Use the 'show' command to run the task and print the resulting value. clean Deletes files produced by the build, such as generated sources, comp… compile Compiles sources. console Starts the Scala interpreter with the project classes on the classpath. … [truncated] 11
  • 12. console > console [info] Starting scala interpreter... [info] Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_60). Type in expressions to have them evaluated. Type :help for more information. (Now we are in Scala console - with main classpath) scala> import com.google.common.base.Splitter import com.google.common.base.Splitter scala> Splitter.on(' ').split("one two three”) res0: Iterable[String] = [one, two, three] scala> example.StringSplit.main(Array[String]()) hello Part: foo Part: bar Part: baz 12
  • 13. More on sbt commands… • Can issue command directly in shell: “sbt run” • Can combine commands: “sbt test package” • clean, publish, publish-local, update, reload • Plugins can add new keys 13
  • 14. Build script So far we have been running only with one file build.sbt in project’s root directory. Behind the scenes, sbt created a Project object and appended the contents of project’s build.sbt to its settings. Manually creating a project by creating a Scala file in project directory…
  • 15. Build script ——————— project/MyBuild.scala ——————————————————————————— import sbt._ import sbt.Keys._ object MyBuild extends Build { lazy val root = (project in file(".")) .settings( name := "MyProj", version := "1.0", scalaVersion := "2.11.6", libraryDependencies += "com.google.guava" % "guava" % "18.0" ) } ————————————————————————————————————————————————— ————————————— Same definition as before with build.sbt file. Settings in build.sbt will be applied on top of this. In fact, any .sbt files in a project, will be merged with the build definition for the entire build, but scoped to that project. 15
  • 16. Scopeslazy val commonSettings = Seq( organization := "com.example", version := "0.1.0", scalaVersion := "2.11.4" ) lazy val core = (project in file("core")) .dependsOn(util) .settings(commonSettings: _*) .settings( name := "projCore" // other settings ) lazy val util = (project in file("util")) .settings(commonSettings: _*) .settings( name := "projUtil" // other settings ) Then in sbt: > util/name [info] projUtil > core/name <— {<build-uri>}<project-id>/config:inkey::key [info] projCore > util/name [info] projUtil > 16
  • 17. Configurations A configuration defines a flavor of build, potentially with its own classpath, sources, generated packages, etc. The configuration concept comes from Ivy, which sbt uses for managed dependencies Library Dependencies, and from MavenScopes. Some configurations you’ll see in sbt: Compile which defines the main build (src/main/scala). Test which defines how to build tests (src/test/scala). Runtime which defines the classpath for the run task. By default, all the keys associated with compiling, packaging, and running are scoped to a configuration and therefore may work differently in each configuration. The most obvious examples are the task keys compile, package, and run; but all the keys which affect those keys (such as sourceDirectories or scalacOptions or fullClasspath) are also scoped to the configuration. 17 Source: http://www.scala-sbt.org/0.13/tutorial/Scopes.html
  • 18. Scopes again In build definition: scalacOptions in Test ++= Seq(“-unchecked") In REPL: Test:scalacOptions General for in REPL is {<build-uri>}<project-id>/config:intask::key 18
  • 19. Plugins A plugin extends the build definition, most commonly by adding new settings, possibly new tasks. For example - if you want to create fat jars, there is a plugin for that: plugin “sbt-assembly”. In project directory create file “assembly.sbt” with the following: addSbtPlugin("com.eed3si9n" % "sbt-assembly" % “0.11.2”) This particular plugin brings in new keys, such as: assembly, assemblyJarName, assemblyMergeStrategy, … Now in sbt, you can run “assembly”: > assembly [info] Including: guava-18.0.jar [info] Including: scala-library-2.11.6.jar [info] Checking every *.class/*.jar file's SHA-1. [info] Merging files... [warn] Merging 'META-INF/MANIFEST.MF' with strategy 'discard' [warn] Merging 'META-INF/maven/com.google.guava/guava/pom.properties' with strategy 'discard' [warn] Merging 'META-INF/maven/com.google.guava/guava/pom.xml' with strategy 'discard' [warn] Strategy 'discard' was applied to 3 files [info] SHA-1: db72fdf182c7c5332a145aa4c018466840f9c554 [info] Packaging /Users/renatb/tmp/sm/my_project/target/scala-2.11/MyProj-assembly-1.0.jar ... [info] Done packaging. [success] Total time: 5 s, completed Apr 1, 2015 11:51:57 PM > 19
  • 20. Delegates A setting has a key and a scope. A request for a key in a scope A may be delegated to another scope if A doesn't define a value for the key. The delegation chain is well-defined and is displayed in the Delegates section of the inspect command. The Delegates section shows the order in which scopes are searched when a value is not defined for the requested key. > inspect console::initialCommands ... [info] Delegates: [info] *:console::initialCommands [info] *:initialCommands [info] {.}/*:console::initialCommands [info] {.}/*:initialCommands [info] */*:console::initialCommands [info] */*:initialCommands ... 20
  • 21. Useful links • http://www.scala-sbt.org/0.13/tutorial/index.html • http://just-thor.com/2013/11/getting-started-with-a- simple-sbt-project/ • http://www.scala-sbt.org/0.13/tutorial/Full-Def.html • http://www.scala-sbt.org/0.13.2/docs/Detailed- Topics/Inspecting-Settings.html 21
  • 22. Upcoming Meetups Seattle Spark Meetup Sparkly Notebook: Interactive Analysis and Visualization with Spark Wednesday, April 15, 2015 - Avvo - 705 5th Ave South #600, Seattle, WA Scala at the Sea Discuss Scala Akka and Related Technologies Tuesday, April 14, 2015 - Whitepages - 1301 5th Avenue #1600, Seattle, WA 22

Editor's Notes

  1. Notice how we are binding a string “MyProj” to a key “name” - we are using an operation ‘:=‘ If our key value is a list, then we can append to it with ‘+=‘. Here libraryDependencies was already defined, and we are now adding another element to it. You will need to learn the keys - e.g. libraryDependencies
  2. Typing the key name into REPL evaluates it: name, version
  3. Another way of looking at the value is using “show”: evaluates the specified task and display the value returned by the task. Another way to find out about a key is with “inspect”: Inspect: shows where this key was defined
  4. Starts the Scala interpreter with the project classes on the classpath.
  5. Starts the Scala interpreter with the project classes on the classpath.
  6. Example of a multi-project build. If core needed util on its classpath, you would define core as. Now that we have 2 projects, our keys can be scoped to specific projects
  7. Example of a multi-project build. If core needed util on its classpath, you would define core as. Now that we have 2 projects, our keys can be scoped to specific projects
  8. Example of a multi-project build. If core needed util on its classpath, you would define core as. Now that we have 2 projects, our keys can be scoped to specific projects
  9. Example of a multi-project build. If core needed util on its classpath, you would define core as. Now that we have 2 projects, our keys can be scoped to specific projects