-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I love this guide. I always recommend it to new people getting starting with sbt. The last couple times I did however they always came back to me ab out certain things not working anymore, mainly the console examples. I decided to just go through the whole thing myself and update all of the examples using a more modern sbt version and updating the output to match. There is also a couple other choices that I made while updating things like: - Changing the weather site we use as an example since it no longer is active - Changing the libraries being used from gigahorse to sttp and Play JSON to uJson. I didn't do this _just because_ but rather to more align with the libraries that are being used by the scala toolkit. Hopefully people will be a bit more familiar with these as I don't assume a newcomer to Scala will be using gigahorse or really Play JSON _unless_ they are using Play!. If this isn't ok, let me know and I can try to recreate it using the old libraries, but I think these examples are clearer.
- Loading branch information
Showing
17 changed files
with
497 additions
and
471 deletions.
There are no files selected for viewing
246 changes: 122 additions & 124 deletions
246
src/reference/00-Getting-Started/02-sbt-by-example.md
Large diffs are not rendered by default.
Oops, something went wrong.
259 changes: 129 additions & 130 deletions
259
src/reference/es/00-Getting-Started/02-sbt-by-example.md
Large diffs are not rendered by default.
Oops, something went wrong.
273 changes: 136 additions & 137 deletions
273
src/reference/ja/00-Getting-Started/02-sbt-by-example.md
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
ThisBuild / scalaVersion := "2.13.6" | ||
ThisBuild / organization := "com.example" | ||
|
||
lazy val hello = (project in file(".")) | ||
lazy val hello = project | ||
.in(file(".")) | ||
.settings( | ||
name := "Hello", | ||
libraryDependencies += "com.typesafe.play" %% "play-json" % "2.9.2", | ||
libraryDependencies += "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0", | ||
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test, | ||
libraryDependencies ++= Seq( | ||
"com.softwaremill.sttp.client4" %% "core" % "4.0.0-M2", | ||
"com.lihaoyi" %% "ujson" % "3.1.2", | ||
"org.scalatest" %% "scalatest" % "3.2.16" % Test | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
ThisBuild / scalaVersion := "2.13.6" | ||
ThisBuild / organization := "com.example" | ||
|
||
lazy val hello = (project in file(".")) | ||
lazy val hello = project | ||
.in(file(".")) | ||
.settings( | ||
name := "Hello", | ||
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test, | ||
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.16" % Test | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
> compile | ||
-> testQuick | ||
$copy-file changes/HelloSpec.scala src/test/scala/HelloSpec.scala | ||
$copy-file changes/HelloSpec.scala src/test/scala/example/HelloSpec.scala | ||
> testQuick |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
ThisBuild / scalaVersion := "2.13.6" | ||
ThisBuild / organization := "com.example" | ||
|
||
lazy val hello = (project in file(".")) | ||
lazy val hello = project | ||
.in(file(".")) | ||
.settings( | ||
name := "Hello", | ||
libraryDependencies += "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0", | ||
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test, | ||
libraryDependencies ++= Seq( | ||
"com.softwaremill.sttp.client4" %% "core" % "4.0.0-M2", | ||
"com.lihaoyi" %% "ujson" % "3.1.2", | ||
"org.scalatest" %% "scalatest" % "3.2.16" % Test | ||
) | ||
) | ||
|
||
lazy val helloCore = (project in file("core")) | ||
lazy val helloCore = project | ||
.in(file("core")) | ||
.settings( | ||
name := "Hello Core", | ||
name := "Hello Core" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
ThisBuild / scalaVersion := "2.13.6" | ||
ThisBuild / organization := "com.example" | ||
|
||
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.7" | ||
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.16" | ||
|
||
lazy val hello = (project in file(".")) | ||
lazy val hello = project | ||
.in(file(".")) | ||
.settings( | ||
name := "Hello", | ||
libraryDependencies += "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0", | ||
libraryDependencies += scalaTest % Test, | ||
libraryDependencies ++= Seq( | ||
"com.softwaremill.sttp.client4" %% "core" % "4.0.0-M2", | ||
"com.lihaoyi" %% "ujson" % "3.1.2", | ||
scalaTest % Test | ||
) | ||
) | ||
|
||
lazy val helloCore = (project in file("core")) | ||
lazy val helloCore = project | ||
.in(file("core")) | ||
.settings( | ||
name := "Hello Core", | ||
libraryDependencies += scalaTest % Test, | ||
libraryDependencies += scalaTest % Test | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
ThisBuild / scalaVersion := "2.13.6" | ||
ThisBuild / organization := "com.example" | ||
|
||
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.7" | ||
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.16" | ||
|
||
lazy val hello = (project in file(".")) | ||
lazy val hello = project | ||
.in(file(".")) | ||
.aggregate(helloCore) | ||
.settings( | ||
name := "Hello", | ||
libraryDependencies += "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0", | ||
libraryDependencies += scalaTest % Test, | ||
libraryDependencies ++= Seq( | ||
"com.softwaremill.sttp.client4" %% "core" % "4.0.0-M2", | ||
"com.lihaoyi" %% "ujson" % "3.1.2", | ||
scalaTest % Test | ||
) | ||
) | ||
|
||
lazy val helloCore = (project in file("core")) | ||
lazy val helloCore = project | ||
.in(file("core")) | ||
.settings( | ||
name := "Hello Core", | ||
libraryDependencies += scalaTest % Test, | ||
libraryDependencies += scalaTest % Test | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
ThisBuild / scalaVersion := "2.13.6" | ||
ThisBuild / organization := "com.example" | ||
|
||
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.7" | ||
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.16" | ||
|
||
lazy val hello = (project in file(".")) | ||
lazy val hello = project | ||
.in(file(".")) | ||
.aggregate(helloCore) | ||
.dependsOn(helloCore) | ||
.settings( | ||
name := "Hello", | ||
libraryDependencies += scalaTest % Test, | ||
libraryDependencies ++= Seq( | ||
"com.softwaremill.sttp.client4" %% "core" % "4.0.0-M2", | ||
"com.lihaoyi" %% "ujson" % "3.1.2", | ||
scalaTest % Test | ||
) | ||
) | ||
|
||
lazy val helloCore = (project in file("core")) | ||
lazy val helloCore = project | ||
.in(file("core")) | ||
.settings( | ||
name := "Hello Core", | ||
libraryDependencies += "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0", | ||
libraryDependencies += scalaTest % Test, | ||
libraryDependencies += scalaTest % Test | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
ThisBuild / scalaVersion := "2.13.6" | ||
ThisBuild / organization := "com.example" | ||
|
||
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.7" | ||
val gigahorse = "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0" | ||
val playJson = "com.typesafe.play" %% "play-json" % "2.9.2" | ||
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.16" | ||
val sttp = "com.softwaremill.sttp.client4" %% "core" % "4.0.0-M2" | ||
val ujson = "com.lihaoyi" %% "ujson" % "3.1.2" | ||
|
||
lazy val hello = (project in file(".")) | ||
lazy val hello = project | ||
.in(file(".")) | ||
.aggregate(helloCore) | ||
.dependsOn(helloCore) | ||
.settings( | ||
name := "Hello", | ||
libraryDependencies += scalaTest % Test, | ||
libraryDependencies += scalaTest % Test | ||
) | ||
|
||
lazy val helloCore = (project in file("core")) | ||
lazy val helloCore = project | ||
.in(file("core")) | ||
.settings( | ||
name := "Hello Core", | ||
libraryDependencies ++= Seq(gigahorse, playJson), | ||
libraryDependencies += scalaTest % Test, | ||
libraryDependencies ++= Seq( | ||
scalaTest % Test, | ||
sttp, | ||
ujson | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
ThisBuild / scalaVersion := "2.13.6" | ||
ThisBuild / organization := "com.example" | ||
|
||
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.7" | ||
val gigahorse = "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0" | ||
val playJson = "com.typesafe.play" %% "play-json" % "2.9.2" | ||
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.16" | ||
val sttp = "com.softwaremill.sttp.client4" %% "core" % "4.0.0-M2" | ||
val ujson = "com.lihaoyi" %% "ujson" % "3.1.2" | ||
|
||
lazy val hello = (project in file(".")) | ||
lazy val hello = project | ||
.in(file(".")) | ||
.aggregate(helloCore) | ||
.dependsOn(helloCore) | ||
.enablePlugins(JavaAppPackaging) | ||
.settings( | ||
name := "Hello", | ||
libraryDependencies += scalaTest % Test, | ||
libraryDependencies += scalaTest % Test | ||
) | ||
|
||
lazy val helloCore = (project in file("core")) | ||
lazy val helloCore = project | ||
.in(file("core")) | ||
.settings( | ||
name := "Hello Core", | ||
libraryDependencies ++= Seq(gigahorse, playJson), | ||
libraryDependencies += scalaTest % Test, | ||
libraryDependencies ++= Seq( | ||
scalaTest % Test, | ||
sttp, | ||
ujson | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
ThisBuild / version := "0.1.0" | ||
ThisBuild / version := "0.1.0" | ||
ThisBuild / scalaVersion := "2.13.6" | ||
ThisBuild / organization := "com.example" | ||
|
||
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.7" | ||
val gigahorse = "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0" | ||
val playJson = "com.typesafe.play" %% "play-json" % "2.9.2" | ||
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.16" | ||
val sttp = "com.softwaremill.sttp.client4" %% "core" % "4.0.0-M2" | ||
val ujson = "com.lihaoyi" %% "ujson" % "3.1.2" | ||
|
||
lazy val hello = (project in file(".")) | ||
lazy val hello = project | ||
.in(file(".")) | ||
.aggregate(helloCore) | ||
.dependsOn(helloCore) | ||
.enablePlugins(JavaAppPackaging) | ||
.settings( | ||
name := "Hello", | ||
libraryDependencies += scalaTest % Test, | ||
libraryDependencies += scalaTest % Test | ||
) | ||
|
||
lazy val helloCore = (project in file("core")) | ||
lazy val helloCore = project | ||
.in(file("core")) | ||
.settings( | ||
name := "Hello Core", | ||
libraryDependencies ++= Seq(gigahorse, playJson), | ||
libraryDependencies += scalaTest % Test, | ||
libraryDependencies ++= Seq( | ||
scalaTest % Test, | ||
sttp, | ||
ujson | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.4") | ||
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.4") |
31 changes: 12 additions & 19 deletions
31
src/sbt-test/ref/example-weather/core/src/main/scala/example/core/Weather.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,19 @@ | ||
package example.core | ||
|
||
import gigahorse._, support.okhttp.Gigahorse | ||
import scala.concurrent._, duration._ | ||
import play.api.libs.json._ | ||
import sttp.client4.quick._ | ||
import sttp.client4.Response | ||
|
||
object Weather { | ||
lazy val http = Gigahorse.http(Gigahorse.config) | ||
|
||
def weather: Future[String] = { | ||
val baseUrl = "https://www.metaweather.com/api/location" | ||
val locUrl = baseUrl + "/search/" | ||
val weatherUrl = baseUrl + "/%s/" | ||
val rLoc = Gigahorse.url(locUrl).get. | ||
addQueryString("query" -> "New York") | ||
import ExecutionContext.Implicits.global | ||
for { | ||
loc <- http.run(rLoc, parse) | ||
woeid = (loc \ 0 \ "woeid").get | ||
rWeather = Gigahorse.url(weatherUrl format woeid).get | ||
weather <- http.run(rWeather, parse) | ||
} yield (weather \\ "weather_state_name")(0).as[String].toLowerCase | ||
def weather() = { | ||
val response: Response[String] = quickRequest | ||
.get( | ||
uri"https://api.open-meteo.com/v1/forecast?latitude=$newYorkLatitude&longitude=$newYorkLongitude¤t_weather=true" | ||
) | ||
.send() | ||
val json = ujson.read(response.body) | ||
json.obj("current_weather")("temperature").num | ||
} | ||
|
||
private def parse = Gigahorse.asString andThen Json.parse | ||
private val newYorkLatitude: Double = 40.7143 | ||
private val newYorkLongitude: Double = -74.006 | ||
} |
8 changes: 3 additions & 5 deletions
8
src/sbt-test/ref/example-weather/src/main/scala/example/Hello.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
package example | ||
|
||
import scala.concurrent._, duration._ | ||
import core.Weather | ||
import example.core.Weather | ||
|
||
object Hello { | ||
def main(args: Array[String]): Unit = { | ||
val w = Await.result(Weather.weather, 10.seconds) | ||
println(s"Hello! The weather in New York is $w.") | ||
Weather.http.close() | ||
val temp = Weather.weather() | ||
println(s"Hello! The current temperature in New York is $temp C.") | ||
} | ||
} |