avro-compiler-extension is an Avro IDL to Java SpecificCompiler extension adding custom IDL annotations, specifically:
- @java-interface type annotation, making given record implement the specified Java interface
- @java-final type annotation, making given record a final Java class
- generated UNION types are no longer automatically generated with Java Object type, but the UNION types common Java interface
Extension is compatible with Avro 1.11.x
Target Java versions is 11
The extension provides following custom annotations. Please see the examples for further information.
The '@java-interface' annotation makes the given record implement the comma separated list of interfaces.
@java-interface("com.example.State")
record StateA {
string name;
}
The '@java-final' annotation makes the given record a final class. This is particularly useful when used in conjunction with sealed interfaces.
@java-final("")
record StateA {
string name;
}
Maven users simply add the avro-compiler-extension extension as a dependency to avro-maven-plugin and set new Velocity template directory and tools class. The following example demonstrates the usage.
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<dependencies>
<dependency>
<groupId>com.github.sabomichal</groupId>
<artifactId>avro-compiler-extension</artifactId>
<version>${avro.compiler.extension.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>idl-protocol</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
<templateDirectory>${project.basedir}/src/main/resources/velocity/</templateDirectory>
<velocityToolsClassesNames>com.github.sabomichal.avroextensions.AvroGeneratorExtensions</velocityToolsClassesNames>
</configuration>
</execution>
</executions>
</plugin>
- first initial version
If you like it, give it a star, if you don't, please write an issue.