Skip to content

Commit

Permalink
Remove direct dependency on circe-derivation due to circe/circe-der…
Browse files Browse the repository at this point in the history
…ivation#346

* Remove internal dependency on `fundamentals-json-circe` (unused)
* Move `CirceTool` from fundamentals-reflection to fundamentals-json-circe
  • Loading branch information
neko-kai committed Feb 5, 2023
1 parent 173a88d commit f540106
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 33 deletions.
17 changes: 9 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -1007,8 +1007,8 @@ lazy val `fundamentals-json-circe` = project.in(file("fundamentals/fundamentals-
),
libraryDependencies ++= { if (scalaVersion.value.startsWith("2.")) Seq(
compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full),
"io.circe" %% "circe-derivation" % V.circe_derivation,
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
"io.circe" %% "circe-derivation" % V.circe_derivation % Test
) else Seq.empty },
libraryDependencies ++= {
val version = scalaVersion.value
Expand Down Expand Up @@ -1164,7 +1164,9 @@ lazy val `fundamentals-json-circe` = project.in(file("fundamentals/fundamentals-
)
case (_, _) => Seq.empty
} },
Test / packageDoc / publishArtifact := false
Test / packageDoc / publishArtifact := false,
Compile / libraryDependencySchemes += "io.circe" %% "circe-core" % VersionScheme.Always,
Compile / libraryDependencySchemes += "io.circe" %% "circe-core_sjs1" % VersionScheme.Always
)
.disablePlugins(AssemblyPlugin)

Expand Down Expand Up @@ -3524,13 +3526,13 @@ lazy val `logstage-core` = project.in(file("logstage/logstage-core"))

lazy val `logstage-rendering-circe` = project.in(file("logstage/logstage-rendering-circe"))
.dependsOn(
`fundamentals-json-circe` % "test->compile;compile->compile",
`logstage-core` % "test->test;compile->compile"
)
.settings(
libraryDependencies ++= Seq(
"org.scala-lang.modules" %% "scala-collection-compat" % V.collection_compat,
"org.scalatest" %% "scalatest" % V.scalatest % Test,
"io.circe" %% "circe-core" % V.circe,
"org.typelevel" %% "jawn-parser" % V.jawn % Test,
"io.circe" %% "circe-parser" % V.circe % Test,
"io.circe" %% "circe-literal" % V.circe % Test,
Expand Down Expand Up @@ -4057,7 +4059,8 @@ lazy val `microsite` = project.in(file("doc/microsite"))
"dev.zio" %% "zio-interop-cats" % V.zio_interop_cats excludeAll("dev.zio" %% "izumi-reflect"),
"dev.zio" %% "izumi-reflect" % V.izumi_reflect,
"org.tpolecat" %% "doobie-core" % V.doobie,
"org.tpolecat" %% "doobie-postgres" % V.doobie
"org.tpolecat" %% "doobie-postgres" % V.doobie,
"io.circe" %% "circe-generic" % V.circe
),
libraryDependencies ++= { if (scalaVersion.value.startsWith("2.")) Seq(
compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full)
Expand Down Expand Up @@ -4695,9 +4698,7 @@ lazy val `izumi` = (project in file("."))
ThisBuild / developers := List(
Developer(id = "7mind", name = "Septimal Mind", url = url("https://github.com/7mind"), email = "[email protected]"),
),
ThisBuild / scmInfo := Some(ScmInfo(url("https://github.com/7mind/izumi"), "scm:git:https://github.com/7mind/izumi.git")),
ThisBuild / libraryDependencySchemes += "io.circe" %% "circe-core" % VersionScheme.Always,
ThisBuild / libraryDependencySchemes += "io.circe" %% "circe-core_sjs1" % VersionScheme.Always
ThisBuild / scmInfo := Some(ScmInfo(url("https://github.com/7mind/izumi"), "scm:git:https://github.com/7mind/izumi.git"))
)
.disablePlugins(AssemblyPlugin)
.aggregate(
Expand Down
2 changes: 1 addition & 1 deletion doc/microsite/src/main/scala/com/example/Entity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import io.circe.Encoder

final case class Entity(id: UUID)
object Entity {
implicit val enc: Encoder.AsObject[Entity] = io.circe.derivation.deriveEncoder[Entity]
implicit val enc: Encoder.AsObject[Entity] = io.circe.generic.semiauto.deriveEncoder[Entity]
}
6 changes: 3 additions & 3 deletions doc/microsite/src/main/tut/logstage/00_logstage.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,14 @@ Example:

```scala mdoc:reset:to-string
import io.circe.Codec
import io.circe.derivation
import io.circe.generic.semiauto
import logstage.LogstageCodec
import logstage.circe.LogstageCirceCodec

final case class KV(key: String, value: Int)

object KV {
implicit val circeCodec: Codec[KV] = derivation.deriveCodec[KV]
implicit val circeCodec: Codec[KV] = semiauto.deriveCodec[KV]
implicit val logstageCodec: LogstageCodec[KV] = LogstageCirceCodec.derived[KV]
}
```
Expand Down Expand Up @@ -394,4 +394,4 @@ You might need to do the following in order for the adapter to properly initiali
```scala
SLF4JBridgeHandler.removeHandlersForRootLogger()
SLF4JBridgeHandler.install()
```
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package izumi.fundamentals.reflection
package izumi.fundamentals.json.circe

import scala.collection.mutable
import scala.language.experimental.macros
Expand All @@ -9,7 +9,7 @@ object CirceTool {
}

class CirceToolMacro(val c: blackbox.Context) {
import c.universe._
import c.universe.*

@inline def make[T: c.WeakTypeTag](): c.Expr[Unit] = {
val all = new mutable.HashSet[Type]()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package izumi.fundamentals.json.circe

import io.circe.derivation.DerivationMacros
import io.circe.{Codec, Decoder, Encoder}

import scala.language.experimental.macros
import scala.reflect.macros.blackbox

// TODO: merge upstream, also with @JsonCodec
final class MaterializeDerivationMacros(override val c: blackbox.Context) extends DerivationMacros(c) {
final class MaterializeDerivationMacros(val c: blackbox.Context) {
import c.universe.*

def materializeEncoderImpl[A: c.WeakTypeTag]: c.Expr[DerivationDerivedEncoder[A]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package izumi.fundamentals.json.circe
import io.circe.Codec

/**
* Requires library dependency on `"io.circe" %% "circe-derivation" % "0.13.0-M5"`
* or later (NOT brought in as a dependency automatically)
*
* Provides circe codecs for case classes and sealed traits
*
* {{{
Expand Down Expand Up @@ -38,6 +41,3 @@ abstract class WithCirce[A]()(implicit derivedCodec: DerivationDerivedCodec[A])

implicit val codec: Codec.AsObject[A] = derivedCodec.value
}



Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import izumi.functional.IzEither.EitherBiAggregate
import scala.annotation.switch
import scala.collection.mutable.ArrayBuffer
import scala.util.control.NonFatal
import JsonFlattener._
import PathElement._
import JsonFlattener.*
import PathElement.*
import izumi.fundamentals.platform.strings.IzEscape

class JsonFlattener {
Expand Down
28 changes: 16 additions & 12 deletions project/Deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ object Izumi {
final val circe_parser = Library("io.circe", "circe-parser", V.circe, LibraryType.Auto)
final val circe_literal = Library("io.circe", "circe-literal", V.circe, LibraryType.Auto)
final val circe_generic = Library("io.circe", "circe-generic", V.circe, LibraryType.Auto)
final val circe_derivation_scala2 = Library("io.circe", "circe-derivation", V.circe_derivation, LibraryType.Auto) in Scope.Compile.all.scalaVersion(
ScalaVersionScope.AllScala2
)
final val circe_derivation_scala2 = Library("io.circe", "circe-derivation", V.circe_derivation, LibraryType.Auto)

final val discipline = Library("org.typelevel", "discipline-core", V.discipline, LibraryType.Auto) in Scope.Test.all
final val discipline_scalatest = Library("org.typelevel", "discipline-scalatest", V.discipline_scalatest, LibraryType.Auto) in Scope.Test.all
Expand Down Expand Up @@ -282,11 +280,6 @@ object Izumi {
Developer(id = "7mind", name = "Septimal Mind", url = url("https://github.com/7mind"), email = "[email protected]"),
)""".raw,
"scmInfo" in SettingScope.Build := """Some(ScmInfo(url("https://github.com/7mind/izumi"), "scm:git:https://github.com/7mind/izumi.git"))""".raw,
// workaround for:
// java.lang.RuntimeException: found version conflict(s) in library dependencies; some are suspected to be binary incompatible:
// +- io.circe:circe-derivation_2.12:0.13.0-M5 (depends on 0.13.0)
"libraryDependencySchemes" in SettingScope.Build += s""""${circe_core.group}" %% "${circe_core.artifact}" % VersionScheme.Always""".raw,
"libraryDependencySchemes" in SettingScope.Build += s""""${circe_core.group}" %% "${circe_core.artifact}_sjs1" % VersionScheme.Always""".raw,
)

final val sharedSettings = Defaults.SbtMetaSharedOptions ++ outOfSource ++ crossScalaSources ++ Seq(
Expand Down Expand Up @@ -341,6 +334,7 @@ object Izumi {
final val typesafeConfig = ArtifactId("fundamentals-typesafe-config")
final val reflection = ArtifactId("fundamentals-reflection")
final val jsonCirce = ArtifactId("fundamentals-json-circe")
final val jsonCirceLegacy = ArtifactId("fundamentals-json-circe-legacy")

final lazy val basics = Seq(
platform,
Expand Down Expand Up @@ -464,15 +458,22 @@ object Izumi {
Artifact(
name = Projects.fundamentals.jsonCirce,
libs = Seq(
scala_reflect,
circe_core in Scope.Compile.all,
circe_generic in Scope.Compile.all.scalaVersion(ScalaVersionScope.AllScala3),
circe_derivation_scala2,
scala_reflect,
) ++ Seq(
circe_derivation_scala2 in Scope.Test.all.scalaVersion(ScalaVersionScope.AllScala2),
jawn in Scope.Test.all,
circe_literal in Scope.Test.all,
),
depends = Seq(Projects.fundamentals.platform),
settings = Seq(
// workaround for:
// java.lang.RuntimeException: found version conflict(s) in library dependencies; some are suspected to be binary incompatible:
// +- io.circe:circe-derivation_2.12:0.13.0-M5 (depends on 0.13.0)
"libraryDependencySchemes" in SettingScope.Compile += s""""${circe_core.group}" %% "${circe_core.artifact}" % VersionScheme.Always""".raw,
"libraryDependencySchemes" in SettingScope.Compile += s""""${circe_core.group}" %% "${circe_core.artifact}_sjs1" % VersionScheme.Always""".raw,
),
),
Artifact(
name = Projects.fundamentals.reflection,
Expand Down Expand Up @@ -620,13 +621,14 @@ object Izumi {
Artifact(
name = Projects.logstage.renderingCirce,
libs = Seq(
circe_core in Scope.Compile.all,
jawn in Scope.Test.all,
circe_parser in Scope.Test.all,
circe_literal in Scope.Test.all,
circe_generic in Scope.Test.all,
zio_core in Scope.Test.all,
),
depends = Seq(Projects.fundamentals.jsonCirce).map(_ in Scope.Compile.all) ++ Seq(Projects.logstage.core).map(_ tin Scope.Compile.all),
depends = Seq(Projects.logstage.core).map(_ tin Scope.Compile.all),
),
Artifact(
name = Projects.logstage.adapterSlf4j,
Expand Down Expand Up @@ -658,7 +660,9 @@ object Izumi {
artifacts = Seq(
Artifact(
name = Projects.docs.microsite,
libs = (allMonads ++ doobie_all).map(_ in Scope.Compile.all),
libs = (allMonads ++ doobie_all).map(_ in Scope.Compile.all) ++ Seq(
circe_generic in Scope.Compile.all
),
depends = all.flatMap(_.artifacts).map(_.name in Scope.Compile.all).distinct,
settings = Seq(
// ignore microsite in IDEA
Expand Down

0 comments on commit f540106

Please sign in to comment.