Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize into multiple sbt projects #45

Merged
merged 5 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion .idea/sbt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/scala_compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,12 @@ That's where TranzactIO comes from. I wanted a way to use ZIO everywhere, and ru

TranzactIO is available on the Sonatype Central Repository (see the Nexus badge on top of this README to get the version number). In your build.sbt:
```sbt
libraryDependencies += "io.github.gaelrenoux" %% "tranzactio" % TranzactIOVersion
// Add this if you use doobie:
libraryDependencies += "io.github.gaelrenoux" %% "tranzactio-doobie" % TranzactIOVersion
// Or this if you use anorm:
libraryDependencies += "io.github.gaelrenoux" %% "tranzactio-anorm" % TranzactIOVersion
```

In addition, you will need to declare the database access library you are using. For instance, with Doobie:
```sbt
libraryDependencies += "org.tpolecat" %% "doobie-core" % DoobieVersion
```



### Imports

Most of the time, you will need to import two packages.
Expand Down
41 changes: 35 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
import BuildHelper._

lazy val tranzactio = (project in file(".")).settings(
name := "tranzactio",
lazy val root = (project in file(".")).settings(
name := "tranzactio-root",
description := "ZIO wrapper for Scala DB libraries (e.g. Doobie, Anorm)",
publish / skip := true,
).aggregate(core, anorm, doobie, examples)

lazy val core = project.settings(
name := "tranzactio-core",
description := "Core classes for Tranzactio",
stdSettings,
publishSettings,
libraryDependencies ++= coreDeps,
)

lazy val anorm = project.settings(
name := "tranzactio-anorm",
description := "ZIO wrapper for Anorm",
stdSettings,
publishSettings,
/* Adds samples as test sources */
Test / unmanagedSourceDirectories ++= Seq(
baseDirectory.value /"src/samples/scala"
),
libraryDependencies ++= anormDeps,
).dependsOn(core)

lazy val doobie = project.settings(
name := "tranzactio-doobie",
description := "ZIO wrapper for Doobie",
stdSettings,
publishSettings,
libraryDependencies ++= doobieDeps,
).dependsOn(core)

lazy val examples = project.settings(
stdSettings,
publish / skip := true,
).dependsOn(
// https://www.scala-sbt.org/1.x/docs/Multi-Project.html#Per-configuration+classpath+dependencies
core % "test->compile;test->test",
anorm % Test,
doobie % Test,
)

/* Makes processes is SBT cancelable without closing SBT */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import zio.test.Assertion._
import zio.test._
import zio.{Scope, ZIO, ZLayer}

/** Integration tests for Doobie */
/** Integration tests for Anorm */
object AnormIT extends ITSpec {

/** Layer is recreated on each test, to have a different database every time. */
Expand Down
17 changes: 9 additions & 8 deletions project/BuildHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ object BuildHelper {
val scala3 = "3.2.2"
}

private val dependencies = Seq(
val coreDeps: Seq[ModuleID] = Seq(
/* ZIO */
"dev.zio" %% "zio" % V.zio,
"dev.zio" %% "zio-streams" % V.zio,
"dev.zio" %% "zio-interop-cats" % V.zioCats,

/* Doobie */
"org.tpolecat" %% "doobie-core" % V.doobie % Optional,
"org.playframework.anorm" %% "anorm" % V.anorm % Optional,

/* ZIO test */
"dev.zio" %% "zio-test" % V.zio % Test,
Expand All @@ -37,12 +32,18 @@ object BuildHelper {
/* H2 for tests */
"com.h2database" % "h2" % V.h2 % Test
)

val anormDeps: Seq[ModuleID] = Seq(
"org.playframework.anorm" %% "anorm" % V.anorm,
)
val doobieDeps: Seq[ModuleID] = Seq(
"dev.zio" %% "zio-interop-cats" % V.zioCats,
"org.tpolecat" %% "doobie-core" % V.doobie,
)

val stdSettings: Seq[Setting[_]] = Seq(
scalaVersion := V.scala3,
crossScalaVersions := Seq(V.scala212, V.scala213, V.scala3),
scalacOptions ++= scalaVersion(ScalacOptions(_)).value,
libraryDependencies ++= dependencies,
Test / fork := true,
Test / testForkedParallel := true, // run tests in parallel on the forked JVM
Test / testOptions += Tests.Argument("-oD"), // show test duration
Expand Down