Search code examples
javascalasbtavrosbt-assembly

Integrating avro into sbt workflow


I'm planning to use Avro schemas in my Scala-based project (built using sbt) and I'm trying to figure out the right way to include the Avro-based classes when building a far jar from my project (using sbt assembly).

Following is the list of steps I had in mind:

(a) Place the avro schema files in src/main/avro

(b) Generate java/scala classes from the schema files into src/main/java or src/main/scala

(c) Generate the fat jar.

Questions

(i) What would be the right way to get step (b) done? I noticed that the Apache Avro project provides a jar named avro-tools-1.8.1.jar to generate java classes from the schema files. However, I'm not sure how this jar file can be used in an sbt-based workflow.

(ii) Another option I noticed is that there are third party sbt plugins (eg: sbt-avrohugger, scavro, sbt-avro, etc.). Is there an sbt plugin that's recommended? Since these are third-party plugins, I couldn't be sure which one's the best.


Solution

  • I'm currently using: sbt-avro

    My configuration is as below in build.sbt:

    seq(sbtavro.SbtAvro.avroSettings: _*)
    (javaSource in avroConfig) := baseDirectory.value / "src/main/java/"
    (stringType in avroConfig) := "String"
    

    To generate the java file manually:

    sbt avro:generate
    

    To generate the fat jar:

    sbt assembly