Avrohugger Maven Plugin

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

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

at.makubi.maven.plugin
ArtifactId

ArtifactId

avrohugger-maven-plugin_2.11
Last Version

Last Version

1.3
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

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

Project URL

https://github.com/makubi/avrohugger-maven-plugin
Source Code Management

Source Code Management

https://github.com/makubi/avrohugger-maven-plugin

Download avrohugger-maven-plugin_2.11

How to add to project

<plugin>
    <groupId>at.makubi.maven.plugin</groupId>
    <artifactId>avrohugger-maven-plugin_2.11</artifactId>
    <version>1.3</version>
</plugin>

Dependencies

compile (4)

Group / Artifact Type Version
org.apache.maven : maven-plugin-api jar 3.3.9
io.spray : spray-json_2.11 jar 1.3.2
org.scala-lang : scala-library jar 2.11.8
com.julianpeeters : avrohugger-core_2.11 jar 0.15.0

provided (1)

Group / Artifact Type Version
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.5

test (5)

Group / Artifact Type Version
junit : junit jar 4.12
org.apache.maven.plugin-testing : maven-plugin-testing-harness jar 3.3.0
org.apache.maven : maven-core jar 3.3.9
org.apache.maven : maven-compat jar 3.3.9
commons-io : commons-io jar 2.5

Project Modules

There are no modules declared in this project.

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

Attention Attention: artifactId changed

Please be aware that the artifactId changed from avrohugger-maven-plugin_2.11 to avrohugger-maven-plugin.

There is no reason to cross-compile Maven plugins, see http://maven.apache.org/guides/mini/guide-maven-classloading.html#Plugin_Classloaders.

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</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate-scala-sources</goal>
            </goals>
        </execution>
    </executions>
</plugin>

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</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

sourceGenerationFormat

  • Format for source code generation
  • Possible values are SCAVRO, SPECIFIC_RECORD and STANDARD
  • Defaults to SPECIFIC_RECORD

namespaceMapping

  • Map namespace in Avro files to custom package name in generated scala files
  • Defaults to Empty List (Namespace is not modified)

fileIncludes

typeOverrides

  • Override for types for generation
  • Possible elements
    • Complex
      • arrayType
      • enumType
      • fixedType
      • mapType
      • protocolType
      • recordType
      • unionType
    • Primitive
      • booleanType
      • bytesType
      • doubleType
      • floatType
      • intType
      • longType
      • nullType
      • stringType
  • Defaults to no overrides

Example

To override the sourceDirectory and outputDirectory, use

<plugins>
    <plugin>
        <groupId>at.makubi.maven.plugin</groupId>
        <artifactId>avrohugger-maven-plugin</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</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>

To override the namespaceMapping of Avro protocols under the com.example.packagename namespace to com.example.packagenamechanged and include all files in a subdirectory and its subdirectories named subdir, use

<plugins>
    <plugin>
        <groupId>at.makubi.maven.plugin</groupId>
        <artifactId>avrohugger-maven-plugin</artifactId>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>generate-scala-sources</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <namespaceMapping>
                <mapping>
                    <from>com.example.packagename</from>
                    <to>com.example.packagenamenew.subchange</to>
                </mapping>
            </namespaceMapping>
            <fileIncludes>
                <fileInclude>
                    <path>subdir/**</path>
                    <matchSyntax>GLOB</matchSyntax>
                </fileInclude>
            </fileIncludes>
        </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.

Versions

Version
1.3
1.2
1.1
1.0