sini / avrohugger-maven-plugin

Maven plugin for generating Scala case classes and ADTs from Apache Avro schemas, datafiles, and protocols

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Avrohugger Maven Plugin

Maven plugin for generating Scala case classes and ADTs from Apache Avro schemas, datafiles, and protocols.

Build Status Maven Central Join the chat at https://gitter.im/julianpeeters/avrohugger

Usage

The plugin currently supports one goal:

  • generate-scala-sources: This generates the Scala sources for the Avro schema
<plugin>
    <groupId>at.makubi.maven.plugin</groupId>
    <artifactId>avrohugger-maven-plugin_${scala.binary.version}</artifactId>
    <version>1.2</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate-scala-sources</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Replace ${scala.binary.version} with the used Scala binary version, e.g. 2.11.

Usage in conjunction with the scala-maven-plugin

This plugin can be used in conjunction with the scala-maven-plugin to add the generated Scala sources to your Scala build.

<plugins>
    <plugin>
        <groupId>at.makubi.maven.plugin</groupId>
        <artifactId>avrohugger-maven-plugin_${scala.binary.version}</artifactId>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>generate-scala-sources</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

    <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <executions>
            <execution>
                <id>add-generated-sources</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>add-source</goal>
                </goals>
                <configuration>
                    <sourceDir>${project.build.directory}/generated-sources/avro</sourceDir>
                </configuration>
            </execution>
            <execution>
                <goals>
                    <goal>compile</goal>
                    <goal>testCompile</goal>
                </goals>
            </execution>
        </executions>
        ...
    </plugin>
</plugins>

Override variables

You can override the following variables in the plugin configuration:

sourceDirectory

  • Path to the directory containing the Avro schema files
  • Defaults to ${basedir}/src/main/avro

outputDirectory

  • Path to the output directory for the generated Scala sources
  • Defaults to ${project.build.directory}/generated-sources/avro

recursive

  • Boolean to allow recursion over the specified sourceDirectory
  • Defaults to false

limitedNumberOfFieldsInCaseClasses

  • Boolean to restrict case class generation for compatibility with scala 2.10
  • Defaults to false

Example

To override the sourceDirectory and outputDirectory, use

<plugins>
    <plugin>
        <groupId>at.makubi.maven.plugin</groupId>
        <artifactId>avrohugger-maven-plugin_${scala.binary.version}</artifactId>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>generate-scala-sources</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <sourceDirectory>src/main/resources/avro</sourceDirectory>
            <outputDirectory>target/generated-sources</outputDirectory>
        </configuration>
    </plugin>
</plugins>

To override the sourceDirectory, outputDirectory, recurse over sourceDirectory, and restrict generated class fields to be compatible with Scala 2.10 use

<plugins>
    <plugin>
        <groupId>at.makubi.maven.plugin</groupId>
        <artifactId>avrohugger-maven-plugin_${scala.binary.version}</artifactId>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>generate-scala-sources</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <sourceDirectory>src/main/resources/avro</sourceDirectory>
            <outputDirectory>target/generated-sources</outputDirectory>
            <recursive>true</recursive>
            <limitedNumberOfFieldsInCaseClasses>true</limitedNumberOfFieldsInCaseClasses>>
        </configuration>
    </plugin>
</plugins>

Dependencies

This plugin heavily relies on Avrohugger to generate Scala code.

Contributors

License

The Avrohugger Maven Plugin is released under version 2.0 of the Apache License.

About

Maven plugin for generating Scala case classes and ADTs from Apache Avro schemas, datafiles, and protocols

License:Apache License 2.0


Languages

Language:Scala 68.5%Language:Java 31.5%