SlideShare a Scribd company logo
SBT
Baby steps
January 2018
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
> agenda
2
[info] build definition
[info] key, task
[info] resolvers
[info] multi-project build
[info] scope
[info] scalacOptions
[info] plugins we use
[maybe[success]] Expected time: 45 min
–Wikipedia
“sbt (Simple Build Tool) is an open-source build tool
for Scala and Java projects…”
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
500 pages of docs
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
> features of SBT
[info] little or no configuration required for simple
projects
[info] scala-based build definition
[info] incremental recompilation
[info] packages and publishes jars, generates docs
[info] supports testing with ScalaCheck, specs, ScalaTest
[info] modularization
[info] external project support (list a git repo as a
dependency)
[info] parallel task/test execution
[info] library management support
[info] more
[success] Total time: 0 s, completed 27/01/2018 6:35:31 PM
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[error] (subs/*:projectDescriptors) Could not create file
/home/svc_jenkins/jenkins_workspace/Substitutability/subs-build-
pr/subs/target/streams/$global/projectDescriptors/$global/streams/outjava.io.IOExcepti
on: No such file or directory
[error] Total time: 0 s, completed Jan 15, 2018 2:39:24 AM
Build step 'Build using sbt' changed build result to FAILURE
Build step 'Build using sbt' marked build as failure
[CHECKSTYLE] Skipping publisher since build result is FAILURE
[WARNINGS] Skipping publisher since build result is FAILURE
Publishing Scoverage XML and HTML report ...
ERROR: Step ?Publish Scoverage Report? aborted due to exception:
java.io.IOException: /home/svc_jenkins/jenkins_workspace/Substitutability/subs-build-
pr/target/scala-2.11/scoverage-report not exists
at
org.jenkinsci.plugins.scoverage.ScoveragePublisher.copyReport(ScoveragePublisher.java:
114)
at
org.jenkinsci.plugins.scoverage.ScoveragePublisher.perform(ScoveragePublisher.java:66)
……
Notified Stash for commit with id f83c0fecc73c477c18843208317f9523a9b17882
Finished: FAILURE
> the basics
[info] build defined in objects extending Build
[info] builds are composed from Projects.
May be local (file) or remote (git url)
[info] projects are a sequence of Settings
[info] settings are key-initialization pairs
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
sbt.version = 0.13.16
build.properties
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
import sbt._
import sbt.Keys._
object ExampleBuild extends Build {
val dependencies = Seq(
"org.scalatest" %% "scalatest" % "1.9.1" % "test"
)
lazy val exampleProject =
Project("example", file(".")) settings(
version := "0.1",
organization := "com.companyname",
scalaVersion := "2.12.4",
libraryDependencies ++= dependencies
)
}
Extending the SBT Build object
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
name := "example"
version := "0.1"
organization := "com.companyname"
scalaVersion := "2.12.4"
libraryDependencies +=
"org.scalatest" %%
"scalatest" % "1.9.1" % "test"
build.sbt file
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
name := "example"
version := "0.1"
organization := "com.companyname"
scalaVersion := "2.12.4"
libraryDependencies +=
"org.scalatest" %%
"scalatest" % "1.9.1" % "test"
build.sbt file
{ }
——— —-————
key operator body
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
build.sbt file
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
:= replace existing
+= add one element
++= add Seq[T](…)
> keys
[info] SettingKey[T]
For static values
name, version, organization
[info] TaskKey[T]
For (re-)computed values
sources, compile
[info] InputKey[T]
For generating a Task from user input
run-main my.main.class
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
Custom Key
lazy val hello = taskKey[Unit]("An example task")
lazy val root = (project in file("."))
.settings(
hello := { println("Hello!") }
)
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
Definition of Task
lazy val hello = taskKey[Unit]("An example task")
lazy val root = (project in file("."))
.settings(
hello := { println("Hello!") }
)
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
> reload
[info] Loading project definition from
/Users/marina/IdeaProjects/example/project
[info] Set current project to example (in build
file:/Users/marina/IdeaProjects/example/)
> hello
Hello!
[success] Total time: 0 s, completed 21/01/2018
9:40:41 PM
>
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
Int Task
lazy val hello = taskKey[Int]("An example task")
lazy val root = (project in file("."))
.settings(
hello := {
println(“Hello!")
2
}
)
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
> show hello
Hello!
[info] 2
[success] Total time: 0 s, completed 21/01/2018 9:40:41 PM
> inspect hello
[info] Task: Int
[info] Description:
[info] An example task
[info] Provided by:
[info] {file:/Users/marina/IdeaProjects/example/}root/*:hello
[info] Defined at:
[info] /Users/marina/IdeaProjects/example/build.sbt:19
[info] Delegates:
[info] *:hello
[info] {.}/*:hello
[info] */*:hello
>
> show, inspect
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
> show package
[info] Packaging
/Users/marina/IdeaProjects/example/target/scala-
2.12/example_2.12-0.1.jar ...
[info] Done packaging.
[info]
/Users/marina/IdeaProjects/example/target/scala-
2.12/example_2.12-0.1.jar
[success] Total time: 0 s, completed 20/01/2018
10:04:01 PM
>
> show package
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
import sbt._
object Dependencies {
object Versions {
val scala = "2.12.4"
val scalatest = "3.0.1"
val shapeless = "2.3.2"
}
val testLibs = Seq(
"org.scalatest" %% "scalatest" % Versions.scalatest
).map(_ % "test")
def mainLibs = Seq(
"com.chuusai" %% "shapeless" % Versions.shapeless,
"org.scala-lang" % "scala-reflect" % Versions.scala
)
}
Dependencies.scala
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
import Dependencies._
name := "example"
version := "0.1"
scalaVersion := "2.12.4"
organization := "com.companyname"
libraryDependencies ++= mainLibs ++ testLibs
build.sbt
libraryDependencies ++= Seq(
groupID % artifactID % revision,
groupID % otherID % otherRevision
)
< artifactID
< revision
< groupID
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
import Dependencies._
name := "example"
version := "0.1"
scalaVersion := "2.12.4"
organization := “com.companyname"
resolvers += "Java.net Maven2 Repository" at
"http://download.java.net/maven/2/"
libraryDependencies ++= mainLibs ++ testLibs
build.sbt
https://www.scala-sbt.org/0.13/docs/Resolvers.html
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
Proxy Repositories
Nexus Artifactory Archiva
OR
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
-Dsbt.repository.config=<path-to-your-repo-file>
OR
Proxy Repositories
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
Nexus Artifactory Archiva
–Wikipedia
Apache Ivy is a transitive package manager.
Build tools and continuous integration servers regularly
support or include Ivy:
• sbt (included in dependency management)
• Jenkins
•…
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
Ivy Maven
sbt
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
MacBook-Pro:IdeaProjects marina$ cd example
MacBook-Pro:example marina$ cd ~/.ivy2
MacBook-Pro:.ivy2 marina$ ls
cache exclude_classifiers exclude_classifiers.lock
MacBook-Pro:.ivy2 marina$ cd cache/
MacBook-Pro:cache marina$ ls
args4j
com.chuusai
com.eed3si9n
com.github.ben-manes.caffeine
com.github.cb372
com.google
com.google.code.findbugs
com.google.code.gson
com.google.guava
com.google.protobuf
com.googlecode.json-simple
com.jcraft
com.lihaoyi
com.lmax
com.squareup.okhttp3
com.squareup.okio
com.thoughtworks.paranamer
com.trueaccord.lenses
com.trueaccord.scalapb
com.typesafe
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
val setts = Seq(
version := "0.1",
scalaVersion := "2.12.4",
organization := "com.companyname"
)
libraryDependencies ++= mainLibs ++ testLibs
lazy val root =
Project(
id = "example",
base = file("."),
dependencies = Seq(
domain,
magnolia
)
)
.settings(setts)
.settings(libraryDependencies ++= mainLibs ++ testLibs)
lazy val magnolia = ProjectRef(
uri("git://github.com/etaty/scalacheck-magnolia.git"),
"scalacheck-magnolia"
)
lazy val domain = Project(
id = "example-domain",
base = file("example-domain"))
.settings(setts)
.settings(moduleName := "domain")
build.sbt
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
Build
root
domain
magnolia
Cloning into ‘/Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia'...
[info] Loading project definition from /Users/marina/IdeaProjects/example/project
[info] Loading project definition from
/Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia/project
[info] Set current project to example (in build file:/Users/marina/IdeaProjects/example/)
[info] Updating {git://github.com/etaty/scalacheck-magnolia.git}scalacheck-magnolia...
[info] downloading
https://repo1.maven.org/maven2/com/propensive/magnolia_2.12/0.6.1/magnolia_2.12-0.6.1.jar
...
[info] [SUCCESSFUL ] com.propensive#magnolia_2.12;0.6.1!magnolia_2.12.jar (2011ms)
[info] downloading
https://repo1.maven.org/maven2/org/scalacheck/scalacheck_2.12/1.13.4/scalacheck_2.12-
1.13.4.jar ...
[info] [SUCCESSFUL ] org.scalacheck#scalacheck_2.12;1.13.4!scalacheck_2.12.jar (4767ms)
[info] Done updating.
[info] Updating {file:/Users/marina/IdeaProjects/example/}example...
[info] Done updating.
[info] Compiling 2 Scala sources to
/Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia/target/scala-
2.12/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.12.4. Compiling...
[info] Compilation completed in 12.795 s
[success] Total time: 28 s, completed 19/01/2018 11:35:13 AM
> compile
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
Cloning into ‘/Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia'...
[info] Loading project definition from /Users/marina/IdeaProjects/example/project
[info] Loading project definition from
/Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia/project
[info] Set current project to example (in build file:/Users/marina/IdeaProjects/example/)
[info] Updating {git://github.com/etaty/scalacheck-magnolia.git}scalacheck-magnolia...
[info] downloading
https://repo1.maven.org/maven2/com/propensive/magnolia_2.12/0.6.1/magnolia_2.12-0.6.1.jar
...
[info] [SUCCESSFUL ] com.propensive#magnolia_2.12;0.6.1!magnolia_2.12.jar (2011ms)
[info] downloading
https://repo1.maven.org/maven2/org/scalacheck/scalacheck_2.12/1.13.4/scalacheck_2.12-
1.13.4.jar ...
[info] [SUCCESSFUL ] org.scalacheck#scalacheck_2.12;1.13.4!scalacheck_2.12.jar (4767ms)
[info] Done updating.
[info] Updating {file:/Users/marina/IdeaProjects/example/}example...
[info] Done updating.
[info] Compiling 2 Scala sources to
/Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia/target/scala-
2.12/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.12.4. Compiling...
[info] Compilation completed in 12.795 s
[success] Total time: 28 s, completed 19/01/2018 11:35:13 AM
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
> compile
Cloning into ‘/Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia'...
[info] Loading project definition from /Users/marina/IdeaProjects/example/project
[info] Loading project definition from
/Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia/project
[info] Set current project to example (in build file:/Users/marina/IdeaProjects/example/)
[info] Updating {git://github.com/etaty/scalacheck-magnolia.git}scalacheck-magnolia...
[info] downloading
https://repo1.maven.org/maven2/com/propensive/magnolia_2.12/0.6.1/magnolia_2.12-0.6.1.jar
...
[info] [SUCCESSFUL ] com.propensive#magnolia_2.12;0.6.1!magnolia_2.12.jar (2011ms)
[info] downloading
https://repo1.maven.org/maven2/org/scalacheck/scalacheck_2.12/1.13.4/scalacheck_2.12-
1.13.4.jar ...
[info] [SUCCESSFUL ] org.scalacheck#scalacheck_2.12;1.13.4!scalacheck_2.12.jar (4767ms)
[info] Done updating.
[info] Updating {file:/Users/marina/IdeaProjects/example/}example...
[info] Done updating.
[info] Compiling 2 Scala sources to
/Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia/target/scala-
2.12/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.12.4. Compiling...
[info] Compilation completed in 12.795 s
[success] Total time: 28 s, completed 19/01/2018 11:35:13 AM
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
> compile
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
> Project
> scope
1. Keys can have different values in
different scopes
• sources in Compile
• sources in Test
2. Keys can be scoped by tasks or
configuration
3. Configurations can extend from each other
• val Test = config("test") extend Compile
The subproject axis
The configuration axis
The task axis
> scope
> scope
Compile, Test
task keys compile, package, run
Project(id = "example-domain")
> referring to scopes in a build definition
lazy val root = (project in file("."))
.settings(
name := "hello"
)
name in Compile := “hello"
name in packageBin := “hello"
name in (Compile, packageBin) := “hello"
> referring to scopes in a build definition
lazy val root = (project in file("."))
.settings(
name := "hello"
)
name in Compile := "hello"
name in packageBin := "hello"
name in (Compile, packageBin) := “hello"
> referring to scopes in a build definition
lazy val root = (project in file("."))
.settings(
name := "hello"
)
name in Compile := "hello"
name in packageBin := "hello"
name in (Compile, packageBin) := "hello"
> scalacOptions
scalacOptions ++= Seq(
"-encoding", "UTF-8",
"-unchecked",
"-deprecation",
"-Ywarn-dead-code"
)
> scalacOptions
scalacOptions ++= Seq(
"-encoding", "UTF-8",
"-unchecked",
"-deprecation",
"-Ywarn-dead-code"
)
> scalacOptions
"-unchecked"
"-deprecation",
"-Ywarn-dead-code"
)
def printListType(lst: List[AnyVal]) = lst match {
case strings: List[String] => println(s"List of Strings
$strList")
case integers: List[Int] => println(s"List of Strings
$intList")
}
> scalacOptions
scalacOptions ++= Seq(
"-encoding", "UTF-8",
"-unchecked",
"-deprecation",
"-Ywarn-dead-code"
)
> scalacOptions
"-deprecation"
"-Ywarn-dead-code"
)
NO OPTION
[warn] there were three deprecation warnings;
re-run with -deprecation for details
WITH OPTION
[warn] Foo.scala:451: method listAll
in class Bar is deprecated: Don't use this method.
Its super broken.
[warn] Bar.listAll(user)
> scalacOptions
scalacOptions ++= Seq(
"-encoding", "UTF-8",
"-unchecked",
"-deprecation",
"-Ywarn-dead-code"
)
> scalacOptions
"-Ywarn-dead-code"
scala> def bar (a: Int): Int = {
| return 0
| a + 10
| }
:12: warning: dead code following this construct
return 0
^
bar: (a: Int)Int
> plugins.sbt
addSbtPlugin("com.eed3si9n" %
"sbt-man" % "0.1.0"
) // look up scaladoc
addSbtPlugin("com.eed3si9n" %
"sbt-dirty-money" % "0.1.0")
// clean Ivy2's cache
addSbtPlugin("com.eed3si9n" %
"sbt-assembly" % "0.14.6")
// create a fat JAR of your project
// with all of its dependencies
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
> assembly
• Merge Strategy
• Shading
• Excluding JARs and files
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
> assembly
•Merge Strategy
Shading
Excluding JARs and files
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
MergeStrategy.deduplicate
verify all files have the same contents & error out otherwise
MergeStrategy.first
picks the first of the matching files in classpath order
MergeStrategy.last picks the last one
MergeStrategy.singleOrError
bails out with an error message on conflict
MergeStrategy.concat
concatenates all matching files and includes the result
MergeStrategy.filterDistinctLines
also concatenates, but leaves out duplicates along the way
MergeStrategy.rename
renames the files originating from jar files
MergeStrategy.discard discards matching files
•Merge Strategy
Shading
Excluding JARs and files
> assembly
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
lazy val root =
Project(
id = "example",
base = file("."),
dependencies = Seq(
domain,
magnolia
)
)
.settings(setts)
.settings(libraryDependencies ++= mainLibs ++ testLibs)
.settings(assemblyJarName in assembly := "example.jar")
.settings(
assemblyMergeStrategy in assembly := {
case "application.conf" => MergeStrategy.concat
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
}
)
•Merge Strategy
Shading
Excluding JARs and files
> assembly
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
> assembly
[info] Including: scala-library-2.12.4.jar
[info] Including: scala-compiler-2.12.4.jar
…
[info] Merging files...
[warn] Merging 'META-INF/MANIFEST.MF' with strategy 'discard'
[warn] Merging 'META-INF/maven/jline/jline/pom.properties'
with strategy 'discard'
[warn] Merging 'META-INF/maven/jline/jline/pom.xml' with
strategy 'discard'
[warn] Merging 'application.conf' with strategy 'concat'
[warn] Merging 'rootdoc.txt' with strategy 'concat'
[warn] Strategy 'concat' was applied to 2 files
[warn] Strategy 'discard' was applied to 3 files
[info] SHA-1: 642c5daa2bfc30a825f08fa72a51a990cac441fc
[info] Packaging /Users/marina/IdeaProjects/example/target/scala-2.12/example.
[info] Done packaging.
Merge Strategy
•Shading
Excluding JARs and files
> assembly
ShadeRule.rename("x.**" -> "y.@1", …)
ShadeRule.zap("a.b.c")
any matched class to be removed from
the resulting jar file
ShadeRule.keep("x.**")
rule marks all matched classes
as "roots"
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
> stackoverflow.com
Merge Strategy
•Shading
Excluding JARs and files
> assembly
.settings(
assemblyShadeRules in assembly := Seq(
ShadeRule.rename("com.google.**" -> "org.moogle.@1").inProject
)
)
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
•Merge Strategy
•Shading
•Excluding JARs and files
> assembly
libraryDependencies ++= Seq(
("org.apache.spark" %% "spark-core" % "0.8.0-incubating")
.exclude("commons-logging", "commons-logging")
)
assemblyMergeStrategy in assembly := {
case PathList("about.html") => MergeStrategy.rename
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
}
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
> summary
[info] Build -> Project -> Settings
[info] s & tasks
[info] Proxy Resolvers
[info] Multi-project build
[info] Scope
[info] scalacOptions
[info] Plugins we use
[success] Total time: 45 min
© 2018 The Quantium Group Pty Ltd. In Commercial Confidence
Thank you!

More Related Content

What's hot

What's hot (20)

Java SE 8 技術手冊第 9 章 - Collection與Map
Java SE 8 技術手冊第 9 章 - Collection與MapJava SE 8 技術手冊第 9 章 - Collection與Map
Java SE 8 技術手冊第 9 章 - Collection與Map
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)
 
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
 
Spark Summit EU talk by Ted Malaska
Spark Summit EU talk by Ted MalaskaSpark Summit EU talk by Ted Malaska
Spark Summit EU talk by Ted Malaska
 
Pandas UDF and Python Type Hint in Apache Spark 3.0
Pandas UDF and Python Type Hint in Apache Spark 3.0Pandas UDF and Python Type Hint in Apache Spark 3.0
Pandas UDF and Python Type Hint in Apache Spark 3.0
 
Capabilities for Resources and Effects
Capabilities for Resources and EffectsCapabilities for Resources and Effects
Capabilities for Resources and Effects
 
Running Apache Spark Jobs Using Kubernetes
Running Apache Spark Jobs Using KubernetesRunning Apache Spark Jobs Using Kubernetes
Running Apache Spark Jobs Using Kubernetes
 
Functional Programming 101 with Scala and ZIO @FunctionalWorld
Functional Programming 101 with Scala and ZIO @FunctionalWorldFunctional Programming 101 with Scala and ZIO @FunctionalWorld
Functional Programming 101 with Scala and ZIO @FunctionalWorld
 
第16回Lucene/Solr勉強会 – ランキングチューニングと定量評価 #SolrJP
第16回Lucene/Solr勉強会 – ランキングチューニングと定量評価 #SolrJP第16回Lucene/Solr勉強会 – ランキングチューニングと定量評価 #SolrJP
第16回Lucene/Solr勉強会 – ランキングチューニングと定量評価 #SolrJP
 
Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)
 
Introduction to Apache Spark
Introduction to Apache SparkIntroduction to Apache Spark
Introduction to Apache Spark
 
Fast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache Calcite
 
PySpark dataframe
PySpark dataframePySpark dataframe
PySpark dataframe
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
Introduction to Spark Internals
Introduction to Spark InternalsIntroduction to Spark Internals
Introduction to Spark Internals
 
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
 
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and ScalaFunctional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
 
Spark
SparkSpark
Spark
 
Javaでやってみる The Twelve Factor App JJUG-CCC 2014 Fall 講演資料
Javaでやってみる The Twelve Factor App JJUG-CCC 2014 Fall 講演資料Javaでやってみる The Twelve Factor App JJUG-CCC 2014 Fall 講演資料
Javaでやってみる The Twelve Factor App JJUG-CCC 2014 Fall 講演資料
 

Similar to Sbt baby steps

Similar to Sbt baby steps (20)

Check Point automatizace a orchestrace
Check Point automatizace a orchestraceCheck Point automatizace a orchestrace
Check Point automatizace a orchestrace
 
Extending uBuild and uDeploy with Plugins
Extending uBuild and uDeploy with PluginsExtending uBuild and uDeploy with Plugins
Extending uBuild and uDeploy with Plugins
 
Masterless Puppet Using AWS S3 Buckets and IAM Roles
Masterless Puppet Using AWS S3 Buckets and IAM RolesMasterless Puppet Using AWS S3 Buckets and IAM Roles
Masterless Puppet Using AWS S3 Buckets and IAM Roles
 
使用 Prometheus 監控 Kubernetes Cluster
使用 Prometheus 監控 Kubernetes Cluster 使用 Prometheus 監控 Kubernetes Cluster
使用 Prometheus 監控 Kubernetes Cluster
 
New and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
New and cool in OSGi R7 - David Bosschaert & Carsten ZiegelerNew and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
New and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
 
Application Modernization with PKS / Kubernetes
Application Modernization with PKS / KubernetesApplication Modernization with PKS / Kubernetes
Application Modernization with PKS / Kubernetes
 
Spring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsugSpring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsug
 
SBT Concepts, part 2
SBT Concepts, part 2SBT Concepts, part 2
SBT Concepts, part 2
 
Best Practices for Scalable Monitoring (ENT310-S) - AWS re:Invent 2018
Best Practices for Scalable Monitoring (ENT310-S) - AWS re:Invent 2018Best Practices for Scalable Monitoring (ENT310-S) - AWS re:Invent 2018
Best Practices for Scalable Monitoring (ENT310-S) - AWS re:Invent 2018
 
Pixels_Camp
Pixels_CampPixels_Camp
Pixels_Camp
 
HP Helion European Webinar Series ,Webinar #3
HP Helion European Webinar Series ,Webinar #3 HP Helion European Webinar Series ,Webinar #3
HP Helion European Webinar Series ,Webinar #3
 
Salesforce meetup | Lightning Web Component
Salesforce meetup | Lightning Web ComponentSalesforce meetup | Lightning Web Component
Salesforce meetup | Lightning Web Component
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
Spring Native and Spring AOT
Spring Native and Spring AOTSpring Native and Spring AOT
Spring Native and Spring AOT
 
Grails At Linked
Grails At LinkedGrails At Linked
Grails At Linked
 
Grails at Linkedin
Grails at LinkedinGrails at Linkedin
Grails at Linkedin
 
State of Steeltoe 2020
State of Steeltoe 2020State of Steeltoe 2020
State of Steeltoe 2020
 
Building Serverless ETL Pipelines
Building Serverless ETL PipelinesBuilding Serverless ETL Pipelines
Building Serverless ETL Pipelines
 
Pivotal Platform - December Release A First Look
Pivotal Platform - December Release A First LookPivotal Platform - December Release A First Look
Pivotal Platform - December Release A First Look
 
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and DataflowHow to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
 

Recently uploaded

ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
Kamal Acharya
 

Recently uploaded (20)

A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
Scaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltageScaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltage
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge
 
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGBRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
 
The Ultimate Guide to External Floating Roofs for Oil Storage Tanks.docx
The Ultimate Guide to External Floating Roofs for Oil Storage Tanks.docxThe Ultimate Guide to External Floating Roofs for Oil Storage Tanks.docx
The Ultimate Guide to External Floating Roofs for Oil Storage Tanks.docx
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Furniture showroom management system project.pdf
Furniture showroom management system project.pdfFurniture showroom management system project.pdf
Furniture showroom management system project.pdf
 
Online resume builder management system project report.pdf
Online resume builder management system project report.pdfOnline resume builder management system project report.pdf
Online resume builder management system project report.pdf
 
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdf
 

Sbt baby steps

  • 2. © 2018 The Quantium Group Pty Ltd. In Commercial Confidence > agenda 2 [info] build definition [info] key, task [info] resolvers [info] multi-project build [info] scope [info] scalacOptions [info] plugins we use [maybe[success]] Expected time: 45 min
  • 3. –Wikipedia “sbt (Simple Build Tool) is an open-source build tool for Scala and Java projects…” © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 4. 500 pages of docs © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 5. > features of SBT [info] little or no configuration required for simple projects [info] scala-based build definition [info] incremental recompilation [info] packages and publishes jars, generates docs [info] supports testing with ScalaCheck, specs, ScalaTest [info] modularization [info] external project support (list a git repo as a dependency) [info] parallel task/test execution [info] library management support [info] more [success] Total time: 0 s, completed 27/01/2018 6:35:31 PM © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 6. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) [error] (subs/*:projectDescriptors) Could not create file /home/svc_jenkins/jenkins_workspace/Substitutability/subs-build- pr/subs/target/streams/$global/projectDescriptors/$global/streams/outjava.io.IOExcepti on: No such file or directory [error] Total time: 0 s, completed Jan 15, 2018 2:39:24 AM Build step 'Build using sbt' changed build result to FAILURE Build step 'Build using sbt' marked build as failure [CHECKSTYLE] Skipping publisher since build result is FAILURE [WARNINGS] Skipping publisher since build result is FAILURE Publishing Scoverage XML and HTML report ... ERROR: Step ?Publish Scoverage Report? aborted due to exception: java.io.IOException: /home/svc_jenkins/jenkins_workspace/Substitutability/subs-build- pr/target/scala-2.11/scoverage-report not exists at org.jenkinsci.plugins.scoverage.ScoveragePublisher.copyReport(ScoveragePublisher.java: 114) at org.jenkinsci.plugins.scoverage.ScoveragePublisher.perform(ScoveragePublisher.java:66) …… Notified Stash for commit with id f83c0fecc73c477c18843208317f9523a9b17882 Finished: FAILURE
  • 7. > the basics [info] build defined in objects extending Build [info] builds are composed from Projects. May be local (file) or remote (git url) [info] projects are a sequence of Settings [info] settings are key-initialization pairs © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 8. © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 9. sbt.version = 0.13.16 build.properties © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 10. import sbt._ import sbt.Keys._ object ExampleBuild extends Build { val dependencies = Seq( "org.scalatest" %% "scalatest" % "1.9.1" % "test" ) lazy val exampleProject = Project("example", file(".")) settings( version := "0.1", organization := "com.companyname", scalaVersion := "2.12.4", libraryDependencies ++= dependencies ) } Extending the SBT Build object © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 11. name := "example" version := "0.1" organization := "com.companyname" scalaVersion := "2.12.4" libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1" % "test" build.sbt file © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 12. name := "example" version := "0.1" organization := "com.companyname" scalaVersion := "2.12.4" libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1" % "test" build.sbt file { } ——— —-———— key operator body © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 13. build.sbt file © 2018 The Quantium Group Pty Ltd. In Commercial Confidence := replace existing += add one element ++= add Seq[T](…)
  • 14. > keys [info] SettingKey[T] For static values name, version, organization [info] TaskKey[T] For (re-)computed values sources, compile [info] InputKey[T] For generating a Task from user input run-main my.main.class © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 15. Custom Key lazy val hello = taskKey[Unit]("An example task") lazy val root = (project in file(".")) .settings( hello := { println("Hello!") } ) © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 16. Definition of Task lazy val hello = taskKey[Unit]("An example task") lazy val root = (project in file(".")) .settings( hello := { println("Hello!") } ) © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 17. > reload [info] Loading project definition from /Users/marina/IdeaProjects/example/project [info] Set current project to example (in build file:/Users/marina/IdeaProjects/example/) > hello Hello! [success] Total time: 0 s, completed 21/01/2018 9:40:41 PM > © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 18. Int Task lazy val hello = taskKey[Int]("An example task") lazy val root = (project in file(".")) .settings( hello := { println(“Hello!") 2 } ) © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 19. > show hello Hello! [info] 2 [success] Total time: 0 s, completed 21/01/2018 9:40:41 PM > inspect hello [info] Task: Int [info] Description: [info] An example task [info] Provided by: [info] {file:/Users/marina/IdeaProjects/example/}root/*:hello [info] Defined at: [info] /Users/marina/IdeaProjects/example/build.sbt:19 [info] Delegates: [info] *:hello [info] {.}/*:hello [info] */*:hello > > show, inspect © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 20. > show package [info] Packaging /Users/marina/IdeaProjects/example/target/scala- 2.12/example_2.12-0.1.jar ... [info] Done packaging. [info] /Users/marina/IdeaProjects/example/target/scala- 2.12/example_2.12-0.1.jar [success] Total time: 0 s, completed 20/01/2018 10:04:01 PM > > show package © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 21. import sbt._ object Dependencies { object Versions { val scala = "2.12.4" val scalatest = "3.0.1" val shapeless = "2.3.2" } val testLibs = Seq( "org.scalatest" %% "scalatest" % Versions.scalatest ).map(_ % "test") def mainLibs = Seq( "com.chuusai" %% "shapeless" % Versions.shapeless, "org.scala-lang" % "scala-reflect" % Versions.scala ) } Dependencies.scala © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 22. import Dependencies._ name := "example" version := "0.1" scalaVersion := "2.12.4" organization := "com.companyname" libraryDependencies ++= mainLibs ++ testLibs build.sbt libraryDependencies ++= Seq( groupID % artifactID % revision, groupID % otherID % otherRevision ) < artifactID < revision < groupID © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 23. import Dependencies._ name := "example" version := "0.1" scalaVersion := "2.12.4" organization := “com.companyname" resolvers += "Java.net Maven2 Repository" at "http://download.java.net/maven/2/" libraryDependencies ++= mainLibs ++ testLibs build.sbt https://www.scala-sbt.org/0.13/docs/Resolvers.html © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 24. Proxy Repositories Nexus Artifactory Archiva OR © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 25. -Dsbt.repository.config=<path-to-your-repo-file> OR Proxy Repositories © 2018 The Quantium Group Pty Ltd. In Commercial Confidence Nexus Artifactory Archiva
  • 26. –Wikipedia Apache Ivy is a transitive package manager. Build tools and continuous integration servers regularly support or include Ivy: • sbt (included in dependency management) • Jenkins •… © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 27. Ivy Maven sbt © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 28. MacBook-Pro:IdeaProjects marina$ cd example MacBook-Pro:example marina$ cd ~/.ivy2 MacBook-Pro:.ivy2 marina$ ls cache exclude_classifiers exclude_classifiers.lock MacBook-Pro:.ivy2 marina$ cd cache/ MacBook-Pro:cache marina$ ls args4j com.chuusai com.eed3si9n com.github.ben-manes.caffeine com.github.cb372 com.google com.google.code.findbugs com.google.code.gson com.google.guava com.google.protobuf com.googlecode.json-simple com.jcraft com.lihaoyi com.lmax com.squareup.okhttp3 com.squareup.okio com.thoughtworks.paranamer com.trueaccord.lenses com.trueaccord.scalapb com.typesafe © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 29. val setts = Seq( version := "0.1", scalaVersion := "2.12.4", organization := "com.companyname" ) libraryDependencies ++= mainLibs ++ testLibs lazy val root = Project( id = "example", base = file("."), dependencies = Seq( domain, magnolia ) ) .settings(setts) .settings(libraryDependencies ++= mainLibs ++ testLibs) lazy val magnolia = ProjectRef( uri("git://github.com/etaty/scalacheck-magnolia.git"), "scalacheck-magnolia" ) lazy val domain = Project( id = "example-domain", base = file("example-domain")) .settings(setts) .settings(moduleName := "domain") build.sbt © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 30. © 2018 The Quantium Group Pty Ltd. In Commercial Confidence Build root domain magnolia
  • 31. Cloning into ‘/Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia'... [info] Loading project definition from /Users/marina/IdeaProjects/example/project [info] Loading project definition from /Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia/project [info] Set current project to example (in build file:/Users/marina/IdeaProjects/example/) [info] Updating {git://github.com/etaty/scalacheck-magnolia.git}scalacheck-magnolia... [info] downloading https://repo1.maven.org/maven2/com/propensive/magnolia_2.12/0.6.1/magnolia_2.12-0.6.1.jar ... [info] [SUCCESSFUL ] com.propensive#magnolia_2.12;0.6.1!magnolia_2.12.jar (2011ms) [info] downloading https://repo1.maven.org/maven2/org/scalacheck/scalacheck_2.12/1.13.4/scalacheck_2.12- 1.13.4.jar ... [info] [SUCCESSFUL ] org.scalacheck#scalacheck_2.12;1.13.4!scalacheck_2.12.jar (4767ms) [info] Done updating. [info] Updating {file:/Users/marina/IdeaProjects/example/}example... [info] Done updating. [info] Compiling 2 Scala sources to /Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia/target/scala- 2.12/classes... [info] 'compiler-interface' not yet compiled for Scala 2.12.4. Compiling... [info] Compilation completed in 12.795 s [success] Total time: 28 s, completed 19/01/2018 11:35:13 AM > compile © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 32. Cloning into ‘/Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia'... [info] Loading project definition from /Users/marina/IdeaProjects/example/project [info] Loading project definition from /Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia/project [info] Set current project to example (in build file:/Users/marina/IdeaProjects/example/) [info] Updating {git://github.com/etaty/scalacheck-magnolia.git}scalacheck-magnolia... [info] downloading https://repo1.maven.org/maven2/com/propensive/magnolia_2.12/0.6.1/magnolia_2.12-0.6.1.jar ... [info] [SUCCESSFUL ] com.propensive#magnolia_2.12;0.6.1!magnolia_2.12.jar (2011ms) [info] downloading https://repo1.maven.org/maven2/org/scalacheck/scalacheck_2.12/1.13.4/scalacheck_2.12- 1.13.4.jar ... [info] [SUCCESSFUL ] org.scalacheck#scalacheck_2.12;1.13.4!scalacheck_2.12.jar (4767ms) [info] Done updating. [info] Updating {file:/Users/marina/IdeaProjects/example/}example... [info] Done updating. [info] Compiling 2 Scala sources to /Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia/target/scala- 2.12/classes... [info] 'compiler-interface' not yet compiled for Scala 2.12.4. Compiling... [info] Compilation completed in 12.795 s [success] Total time: 28 s, completed 19/01/2018 11:35:13 AM © 2018 The Quantium Group Pty Ltd. In Commercial Confidence > compile
  • 33. Cloning into ‘/Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia'... [info] Loading project definition from /Users/marina/IdeaProjects/example/project [info] Loading project definition from /Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia/project [info] Set current project to example (in build file:/Users/marina/IdeaProjects/example/) [info] Updating {git://github.com/etaty/scalacheck-magnolia.git}scalacheck-magnolia... [info] downloading https://repo1.maven.org/maven2/com/propensive/magnolia_2.12/0.6.1/magnolia_2.12-0.6.1.jar ... [info] [SUCCESSFUL ] com.propensive#magnolia_2.12;0.6.1!magnolia_2.12.jar (2011ms) [info] downloading https://repo1.maven.org/maven2/org/scalacheck/scalacheck_2.12/1.13.4/scalacheck_2.12- 1.13.4.jar ... [info] [SUCCESSFUL ] org.scalacheck#scalacheck_2.12;1.13.4!scalacheck_2.12.jar (4767ms) [info] Done updating. [info] Updating {file:/Users/marina/IdeaProjects/example/}example... [info] Done updating. [info] Compiling 2 Scala sources to /Users/marina/.sbt/0.13/staging/8924b22f06679a54873e/scalacheck-magnolia/target/scala- 2.12/classes... [info] 'compiler-interface' not yet compiled for Scala 2.12.4. Compiling... [info] Compilation completed in 12.795 s [success] Total time: 28 s, completed 19/01/2018 11:35:13 AM © 2018 The Quantium Group Pty Ltd. In Commercial Confidence > compile
  • 34. © 2018 The Quantium Group Pty Ltd. In Commercial Confidence > Project
  • 35. > scope 1. Keys can have different values in different scopes • sources in Compile • sources in Test 2. Keys can be scoped by tasks or configuration 3. Configurations can extend from each other • val Test = config("test") extend Compile
  • 36. The subproject axis The configuration axis The task axis > scope
  • 37. > scope Compile, Test task keys compile, package, run Project(id = "example-domain")
  • 38. > referring to scopes in a build definition lazy val root = (project in file(".")) .settings( name := "hello" ) name in Compile := “hello" name in packageBin := “hello" name in (Compile, packageBin) := “hello"
  • 39. > referring to scopes in a build definition lazy val root = (project in file(".")) .settings( name := "hello" ) name in Compile := "hello" name in packageBin := "hello" name in (Compile, packageBin) := “hello"
  • 40. > referring to scopes in a build definition lazy val root = (project in file(".")) .settings( name := "hello" ) name in Compile := "hello" name in packageBin := "hello" name in (Compile, packageBin) := "hello"
  • 41. > scalacOptions scalacOptions ++= Seq( "-encoding", "UTF-8", "-unchecked", "-deprecation", "-Ywarn-dead-code" )
  • 42. > scalacOptions scalacOptions ++= Seq( "-encoding", "UTF-8", "-unchecked", "-deprecation", "-Ywarn-dead-code" )
  • 43. > scalacOptions "-unchecked" "-deprecation", "-Ywarn-dead-code" ) def printListType(lst: List[AnyVal]) = lst match { case strings: List[String] => println(s"List of Strings $strList") case integers: List[Int] => println(s"List of Strings $intList") }
  • 44. > scalacOptions scalacOptions ++= Seq( "-encoding", "UTF-8", "-unchecked", "-deprecation", "-Ywarn-dead-code" )
  • 45. > scalacOptions "-deprecation" "-Ywarn-dead-code" ) NO OPTION [warn] there were three deprecation warnings; re-run with -deprecation for details WITH OPTION [warn] Foo.scala:451: method listAll in class Bar is deprecated: Don't use this method. Its super broken. [warn] Bar.listAll(user)
  • 46. > scalacOptions scalacOptions ++= Seq( "-encoding", "UTF-8", "-unchecked", "-deprecation", "-Ywarn-dead-code" )
  • 47. > scalacOptions "-Ywarn-dead-code" scala> def bar (a: Int): Int = { | return 0 | a + 10 | } :12: warning: dead code following this construct return 0 ^ bar: (a: Int)Int
  • 48. > plugins.sbt addSbtPlugin("com.eed3si9n" % "sbt-man" % "0.1.0" ) // look up scaladoc addSbtPlugin("com.eed3si9n" % "sbt-dirty-money" % "0.1.0") // clean Ivy2's cache addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6") // create a fat JAR of your project // with all of its dependencies © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 49. > assembly • Merge Strategy • Shading • Excluding JARs and files © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 50. > assembly •Merge Strategy Shading Excluding JARs and files © 2018 The Quantium Group Pty Ltd. In Commercial Confidence MergeStrategy.deduplicate verify all files have the same contents & error out otherwise MergeStrategy.first picks the first of the matching files in classpath order MergeStrategy.last picks the last one MergeStrategy.singleOrError bails out with an error message on conflict MergeStrategy.concat concatenates all matching files and includes the result MergeStrategy.filterDistinctLines also concatenates, but leaves out duplicates along the way MergeStrategy.rename renames the files originating from jar files MergeStrategy.discard discards matching files
  • 51. •Merge Strategy Shading Excluding JARs and files > assembly © 2018 The Quantium Group Pty Ltd. In Commercial Confidence lazy val root = Project( id = "example", base = file("."), dependencies = Seq( domain, magnolia ) ) .settings(setts) .settings(libraryDependencies ++= mainLibs ++ testLibs) .settings(assemblyJarName in assembly := "example.jar") .settings( assemblyMergeStrategy in assembly := { case "application.conf" => MergeStrategy.concat case x => val oldStrategy = (assemblyMergeStrategy in assembly).value oldStrategy(x) } )
  • 52. •Merge Strategy Shading Excluding JARs and files > assembly © 2018 The Quantium Group Pty Ltd. In Commercial Confidence > assembly [info] Including: scala-library-2.12.4.jar [info] Including: scala-compiler-2.12.4.jar … [info] Merging files... [warn] Merging 'META-INF/MANIFEST.MF' with strategy 'discard' [warn] Merging 'META-INF/maven/jline/jline/pom.properties' with strategy 'discard' [warn] Merging 'META-INF/maven/jline/jline/pom.xml' with strategy 'discard' [warn] Merging 'application.conf' with strategy 'concat' [warn] Merging 'rootdoc.txt' with strategy 'concat' [warn] Strategy 'concat' was applied to 2 files [warn] Strategy 'discard' was applied to 3 files [info] SHA-1: 642c5daa2bfc30a825f08fa72a51a990cac441fc [info] Packaging /Users/marina/IdeaProjects/example/target/scala-2.12/example. [info] Done packaging.
  • 53. Merge Strategy •Shading Excluding JARs and files > assembly ShadeRule.rename("x.**" -> "y.@1", …) ShadeRule.zap("a.b.c") any matched class to be removed from the resulting jar file ShadeRule.keep("x.**") rule marks all matched classes as "roots" © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 55. Merge Strategy •Shading Excluding JARs and files > assembly .settings( assemblyShadeRules in assembly := Seq( ShadeRule.rename("com.google.**" -> "org.moogle.@1").inProject ) ) © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 56. •Merge Strategy •Shading •Excluding JARs and files > assembly libraryDependencies ++= Seq( ("org.apache.spark" %% "spark-core" % "0.8.0-incubating") .exclude("commons-logging", "commons-logging") ) assemblyMergeStrategy in assembly := { case PathList("about.html") => MergeStrategy.rename case x => val oldStrategy = (assemblyMergeStrategy in assembly).value oldStrategy(x) } © 2018 The Quantium Group Pty Ltd. In Commercial Confidence
  • 57. > summary [info] Build -> Project -> Settings [info] s & tasks [info] Proxy Resolvers [info] Multi-project build [info] Scope [info] scalacOptions [info] Plugins we use [success] Total time: 45 min © 2018 The Quantium Group Pty Ltd. In Commercial Confidence