Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Useful SBT plugins

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Useful SBT plugins

Avatar for Alexey Novakov

Alexey Novakov

April 30, 2020
Tweet

More Decks by Alexey Novakov

Other Decks in Programming

Transcript

  1. ABOUT ME ➤ Solution Architect at Ultra Tendency, Germany ➤

    Experience: ➤ Scala - 5yrs. ➤ Java - 10 yrs. ➤ Big Data, Kubernetes ➤ My interests: ➤ 8 string guitars ➤ Astronomy ➤ FP ➤ Rust
  2. SBT Tasks (commands) sbt clean - deletes previously built files

    sbt compile - compiles source code sbt test - run tests, if any exists sbt run - runs detected “Main” class sbt package - makes jar file … user can define new tasks in *.sbt files Alexey Novakov, Ultra Tendency, 2020
  3. Scala IDEs IntelliJ + Scala Plugin VSCode + Metals (Scala

    LSP) Alexey Novakov, Ultra Tendency, 2020
  4. Build Definition build.sbt: Alexey Novakov, Ultra Tendency, 2020 import Dependencies._

    ThisBuild / scalaVersion := "2.13.1" ThisBuild / version := "0.1.0-SNAPSHOT" ThisBuild / organization := "com.example" ThisBuild / organizationName := "example" lazy val root = (project in file(".")) .settings( name := "akka-http-api", libraryDependencies += scalaTest % Test ) Scope: build level, default for all sub-projects
  5. Managed Dependencies import Dependencies._ lazy val root = (project in

    file(".")) .settings( libraryDependencies += scalaTest % Test ) import sbt._ object Dependencies { lazy val scalaTest = "org.scalatest" %% "scalatest" % “3.0.8" } Alexey Novakov, Ultra Tendency, 2020 build.sbt project/ Dependencies.scala
  6. libraryDependencies += “org.scalatest" %% "scalatest" % "3.0.8" % Test groupID

    % artifactID % revision % configuration "org.scalatest" % “scalatest_2.13” % "3.0.8" % Test %% - matches current build Scala version Alexey Novakov, Ultra Tendency, 2020
  7. - SBT is using Coursier to download Ivy or Maven

    dependencies Coursier - Pure Scala Artifact Fetching Alexey Novakov, Ultra Tendency, 2020
  8. Giter8 allows to create your own project template and host

    on GitHub: sbt new novakov-alexey/scalaboot.g8 —> https://github.com/novakov-alexey/scalaboot.g8 Alexey Novakov, Ultra Tendency, 2020
  9. ThisBuild / organization := "com.example" ThisBuild / scalaVersion := "$scalaVersion$"

    ThisBuild / description := "$desc$" lazy val root = (project in file(".")). settings( name := "$name;format="lower,hyphen"$", libraryDependencies ++= Seq( akkaHttp, akkaStreams, scalaLogging, logback, … parameters
  10. name=Project Name desc=Describe your project a bit scalaVersion=2.13.1 src/main/g8/default.properties [info]

    Loading settings for project global-plugins from idea.sbt,gpg.sbt ... [info] Loading global plugins from /Users/alexey/.sbt/1.0/plugins [info] Set current project to git (in build file:/Users/alexey/dev/git/) name [Project Name]: app-1 desc [Describe your project a bit]: order registration scalaVersion [2.13.1]: 2.13.2 Template applied in /Users/alexey/dev/git/./app-1
  11. 2. sbt-revolver - restarts running application automatically, if source files

    are modified addSbtPlugin("io.spray" % "sbt-revolver" % “x.y.z") sbt “~reStart” - enables a super-fast development turnaround for your Scala applications Alexey Novakov, Ultra Tendency, 2020
  12. configuration javaOptions in reStart += "-Xmx2g" mainClass in reStart :=

    Some("com.example.Main") Revolver.enableDebugging(port = 5050, suspend = true) envVars in reStart := Map(“K8S_NAMESPACE" -> “test") Alexey Novakov, Ultra Tendency, 2020
  13. • sbt-revolver -> SBT Triggered Execution > ~ testQuick >

    ~ testOnly org.alexeyn.SomeTest > ~ test > ~ clean; test ~tilde Alexey Novakov, Ultra Tendency, 2020
  14. 3. sbt-tpolecat addSbtPlugin( “io.github.davidgregory084" % "sbt-tpolecat" % “0.1.10" ) -

    enables scalac options according to Rob Noris (doobie) recommendations - P.S. the same options can be enabled manually, but why bother Alexey Novakov, Ultra Tendency, 2020
  15. scalacOptions ++= Seq( "-deprecation", "-encoding", "utf-8", "-explaintypes", "-language:higherKinds", "-language:implicitConversions", "-unchecked",

    "-Xfatal-warnings", "-Xlint:infer-any", "-Ywarn-dead-code", "-Ywarn-extra-implicit", "-Ywarn-inaccessible", "-Ywarn-infer-any", "-Ywarn-numeric-widen", "-Ywarn-unused:implicits", "-Ywarn-unused:imports", "-Ywarn-unused:locals", "-Ywarn-unused:params", "-Ywarn-unused:patvars", "-Ywarn-unused:privates", "-Ywarn-value-discard" … ) ~54 Scala Compiler Options Enabled Automatically Alexey Novakov, Ultra Tendency, 2020
  16. 4. sbt-native-packager lets you build application packages in native formats:

    •universal zip, tar.gz, xz archives •deb and rpm packages •dmg •msi •docker images •graalvm native images addSbtPlugin("com.typesafe.sbt" %% "sbt-native-packager" % “x.y.z") Alexey Novakov, Ultra Tendency, 2020
  17. usage lazy val root = (project in file(".")). settings( name

    := "exchange", …. dockerBaseImage := “openjdk:8-jre-alpine”, dockerExposedPorts ++= Seq(8080), dockerRepository := Some(“alexeyn") ).enablePlugins(AshScriptPlugin) // DockerPlugin, JavaAppPackaging
  18. [info] * Cmd(FROM,WrappedArray(openjdk:8, as, stage0)) [info] * Cmd(LABEL,WrappedArray(snp-multi-stage="intermediate")) [info] *

    Cmd(LABEL,WrappedArray(snp-multi-stage-id="b8437d6f-af0a-459c-ae51-cd3b9c5b7404")) [info] * Cmd(WORKDIR,WrappedArray(/opt/docker)) [info] * Cmd(COPY,WrappedArray(opt /opt)) [info] * Cmd(USER,WrappedArray(root)) [info] * ExecCmd(RUN,List(chmod, -R, u=rX,g=rX, /opt/docker)) [info] * ExecCmd(RUN,List(chmod, u+x,g+x, /opt/docker/bin/exchange)) dockerCommands := Seq( Cmd("FROM", "openjdk:8"), Cmd("LABEL", s"""MAINTAINER="${maintainer.value}""""), ExecCmd("CMD", "echo", "Hello, World from Docker") )
  19. 5. sbt-release addSbtPlugin( "com.github.gseitz" % "sbt-release" % “1.0.12" ) provides

    customisable release process … Alexey Novakov, Ultra Tendency, 2020
  20. releaseProcess := Seq[ReleaseStep]( checkSnapshotDependencies, inquireVersions, runTest, setReleaseVersion, commitReleaseVersion, tagRelease, publishArtifacts,

    inquireVersions, setNextVersion, commitNextVersion, pushChanges ) Default list of steps: sbt 'release with-defaults' includes
  21. releaseProcess := Seq[ReleaseStep]( checkSnapshotDependencies, inquireVersions, runTest, setReleaseVersion, commitReleaseVersion, tagRelease, publishArtifacts,

    inquireVersions, setNextVersion, commitNextVersion, pushChanges ) Alexey Novakov, Ultra Tendency, 2020 $PROJECT_ROOT/version.sbt version in ThisBuild := "0.1.1-SNAPSHOT" version in ThisBuild := “0.1.1" version in ThisBuild := “0.1.2-SNAPSHOT" build.sbt: sbt 'release with-defaults' 1 2 3
  22. commit 99b1094dce14bf99b6f38a8ff9870edaf7c728d3 (HEAD -> master, origin/master) Date: Fri Feb 7

    09:20:03 2020 +0100 Setting version to 0.1.2-SNAPSHOT commit cb9ec293a11a5f6d989c936b18922d3f3ec40bcd (tag: v0.2.2) Date: Fri Feb 7 09:16:59 2020 +0100 Setting version to 0.1.1 commit 63abea7141901419ad732d354dc703f884e53010 Merge: b180810 a1c0c14 Date: Fri Feb 7 08:57:00 2020 +0100 Merge pull request #35 from novakov-alexey/add-cookier-attributes add string property attributes to put user defined parameters into th… setNextVersion setReleaseVersion time
  23. Thank you! Questions? Alexey Novakov email: - alexey.novakov at ultratendency.com

    - novakov.alex at gmail.com Blog: https://novakov-alexey.github.io/ https://medium.com/se-notes-by-alexey-novakov Code: https://github.com/novakov-alexey Twitter: @alexey_novakov