Skip to content

Commit

Permalink
Reorganize into multiple sbt projects (#45)
Browse files Browse the repository at this point in the history
(This introduces a change in the project dependencies)
  • Loading branch information
thanhbv authored Jul 29, 2023
1 parent 038cfd5 commit e05778a
Show file tree
Hide file tree
Showing 39 changed files with 63 additions and 29 deletions.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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

0 comments on commit e05778a

Please sign in to comment.