Skip to content

Commit

Permalink
Cross-compile against 2.11 and 2.12
Browse files Browse the repository at this point in the history
  • Loading branch information
NeQuissimus committed May 11, 2018
1 parent 1049be0 commit 4d80018
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ Implicitly turn your `Encoder` and `Decoder` instances into `Serializer`, `Deser

## Artifact

`circe-kafka` is cross-compiled against Scala 2.11 and 2.12.

```scala
libraryDependencies ++= "com.nequissimus" %% "circe-kafka" % "1.0.0"
libraryDependencies ++= "com.nequissimus" %% "circe-kafka" % "1.0.1"
```

## Usage
Expand Down
31 changes: 20 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
scalaVersion in ThisBuild := "2.12.6"
scalaVersion := "2.12.6"
crossScalaVersions := Seq("2.11.12", "2.12.6")

organization := "com.nequissimus"
name := "circe-kafka"
version := "1.0.1-SNAPSHOT"
version := "1.0.1"

// https://tpolecat.github.io/2017/04/25/scalac-flags.html
scalacOptions ++= Seq(
val scalac212Options = Seq(
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.
"-Ywarn-unused:implicits", // Warn if an implicit parameter is unused.
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-unused:locals", // Warn if a local definition is unused.
"-Ywarn-unused:params", // Warn if a value parameter is unused.
"-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
"-Ywarn-unused:privates", // Warn if a private member is unused.
)

val scalac211Options = Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding", "utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
Expand All @@ -20,7 +32,6 @@ scalacOptions ++= Seq(
"-Xfuture", // Turn on future language features.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:by-name-right-associative", // By-name parameter of right associative operator.
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
Expand All @@ -38,21 +49,19 @@ scalacOptions ++= Seq(
"-Yno-adapted-args", // Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver.
"-Ypartial-unification", // Enable partial unification in type constructor inference
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.
"-Ywarn-inaccessible", // Warn about inaccessible types in method signatures.
"-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
"-Ywarn-nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Ywarn-nullary-unit", // Warn when nullary methods return Unit.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-Ywarn-unused:implicits", // Warn if an implicit parameter is unused.
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-unused:locals", // Warn if a local definition is unused.
"-Ywarn-unused:params", // Warn if a value parameter is unused.
"-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
"-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-value-discard" // Warn when non-Unit expression results are unused.
)

scalacOptions := (CrossVersion.partialVersion(scalaBinaryVersion.value) match {
case Some((2, v)) if v == 11 => scalac211Options
case _ => scalac211Options ++ scalac212Options
})

libraryDependencies ++= Seq(
"io.circe" %% "circe-core" % "0.9.3",
"io.circe" %% "circe-generic" % "0.9.3" % Test,
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/ImplicitSerde.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package object kafka {
implicit def deserializer[T](implicit decoder: Decoder[T]): Deserializer[T] = new Deserializer[T] {
def close(): Unit = {}
@silent def configure(config: JMap[String, _], isKey: Boolean): Unit = {}
def deserialize(topic: String, data: Array[Byte]): T = decode[T](new String(data)).getOrElse(null.asInstanceOf[T])
def deserialize(topic: String, data: Array[Byte]): T = decode[T](new String(data)).fold(_ => null.asInstanceOf[T], identity)
}

implicit def serde[T](implicit serializer: Serializer[T], deserializer: Deserializer[T]): Serde[T] = Serdes.serdeFrom(serializer, deserializer)
Expand Down

0 comments on commit 4d80018

Please sign in to comment.