Skip to content

Commit

Permalink
Expose avro compiler version (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
RustedBones authored Aug 1, 2022
1 parent 9401702 commit 174e075
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 10 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ libraryDependencies += "org.apache.avro" % "avro-compiler" % "1.11.0"
Add the library dependency to `build.sbt`:

```
// Version must match that of `avro-compiler` in `project/plugins.sbt`
libraryDependencies += "org.apache.avro" % "avro" % "1.11.0"
libraryDependencies += "org.apache.avro" % "avro" % avroCompilerVersion
```

## Settings
Expand Down
13 changes: 12 additions & 1 deletion src/main/scala/com/github/sbt/avro/SbtAvro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.github.sbt.avro.mojo.{AvroFileRef, SchemaParserBuilder}
import sbt.librarymanagement.DependencyFilter

import java.io.File
import java.util.jar.JarFile

/**
* Simple plugin for generating the Java sources for Avro schemas and protocols.
Expand All @@ -21,7 +22,15 @@ object SbtAvro extends AutoPlugin {

val AvroClassifier = "avro"

private val avroCompilerVersion = classOf[SpecificCompiler].getPackage.getImplementationVersion
// since 1.10, avro defines Implementation-Version in artifact manifest
private def implVersion = Option(classOf[SpecificCompiler].getPackage.getImplementationVersion)

// avro defines OSGI Bundle-Version in artifact manifest
private def bundleVersion = {
val location = classOf[SpecificCompiler].getProtectionDomain.getCodeSource.getLocation
val jar = new JarFile(new File(location.toURI))
jar.getManifest.getMainAttributes.getValue("Bundle-Version")
}

private val AvroAvrpFilter: NameFilter = "*.avpr"
private val AvroAvdlFilter: NameFilter = "*.avdl"
Expand All @@ -34,6 +43,8 @@ object SbtAvro extends AutoPlugin {

import Defaults._

lazy val avroCompilerVersion: String = implVersion.getOrElse(bundleVersion)

// format: off
val avroStringType = settingKey[String]("Type for representing strings. Possible values: CharSequence, String, Utf8. Default: CharSequence.")
val avroEnableDecimalLogicalType = settingKey[Boolean]("Set to true to use java.math.BigDecimal instead of java.nio.ByteBuffer for logical type \"decimal\".")
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/basic_1.10/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name := "basic-test"
scalaVersion := "2.13.6"
libraryDependencies += "org.apache.avro" % "avro" % "1.10.2" // scala-steward:off
libraryDependencies += "org.apache.avro" % "avro" % avroCompilerVersion
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/basic_1.8/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name := "basic-test"
scalaVersion := "2.13.6"
libraryDependencies += "org.apache.avro" % "avro" % "1.8.2" // scala-steward:off
libraryDependencies += "org.apache.avro" % "avro" % avroCompilerVersion
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/basic_1.9/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name := "basic-test"
scalaVersion := "2.13.6"
libraryDependencies += "org.apache.avro" % "avro" % "1.9.2" // scala-steward:off
libraryDependencies += "org.apache.avro" % "avro" % avroCompilerVersion
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/basic_current/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name := "basic-test"
scalaVersion := "2.13.6"
libraryDependencies += "org.apache.avro" % "avro" % "1.11.0" // scala-steward:off
libraryDependencies += "org.apache.avro" % "avro" % avroCompilerVersion
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/publishing/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lazy val commonSettings = Seq(
publishTo := Some(Opts.resolver.sonatypeReleases),
scalaVersion := "2.13.6",
libraryDependencies ++= Seq(
"org.apache.avro" % "avro" % "1.11.0"
"org.apache.avro" % "avro" % avroCompilerVersion
)
)

Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/sbt_1.3/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name := "basic-test"
scalaVersion := "2.13.6"
libraryDependencies += "org.apache.avro" % "avro" % "1.11.0"
libraryDependencies += "org.apache.avro" % "avro" % avroCompilerVersion
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/settings/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name := "settings-test"
scalaVersion := "2.13.6"
libraryDependencies ++= Seq(
"org.apache.avro" % "avro" % "1.11.0",
"org.apache.avro" % "avro" % avroCompilerVersion,
"org.specs2" %% "specs2-core" % "4.16.1" % Test
)

Expand Down

0 comments on commit 174e075

Please sign in to comment.