Skip to main content

Avro Maven plugin

jeap-messaging-avro-maven-plugin generates Java classes from Avro definitions and binds them to the jEAP message interfaces, so the generated event/command classes implement the model types from jeap-messaging-avro / jeap-messaging-model.

Most services do not run this plugin directly: their message-type classes arrive as Maven dependencies from the Message Type Registry, which builds them with this same plugin. You use the plugin directly when you keep Avro definitions in your own repository — for example a shared message library, or local/dev message types not yet in the registry.

Goals

GoalInputDefault phasePurpose
idl.avdl (Avro IDL)generate-sourcesGenerate Java from Avro IDL files
protocol.avpr (Avro protocol)generate-sourcesGenerate Java from Avro protocol files
schema.avsc (Avro schema)process-resourcesGenerate Java from Avro schema files
compile-message-typesregistry descriptor/ treegenerate-sourcesBuild a whole Message Type Registry into per-type Maven modules
deploy-message-type-artifactsgenerated modulesdeployDeploy the generated message-type JARs

idl, protocol and schema are the goals an application or message library uses. The last two are used inside a Message Type Registry build and are documented under Message Type Registry.

Generating classes from Avro IDL

Add jeap-messaging-avro (it provides the base types the generated classes reference) and run the idl goal on the .avdl files in src/main/avro:

<dependency>
<groupId>ch.admin.bit.jeap</groupId>
<artifactId>jeap-messaging-avro</artifactId>
</dependency>
<plugin>
<groupId>ch.admin.bit.jeap</groupId>
<artifactId>jeap-messaging-avro-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>idl</goal>
</goals>
</execution>
</executions>
</plugin>

Use schema or protocol instead of (or alongside) idl if your definitions are .avsc or .avpr files. In Avro IDL, import the jEAP base types with import idl "DomainEventBaseTypes.avdl"; (events) or import idl "MessagingBaseTypes.avdl"; (commands).

Parameters

The idl, protocol and schema goals share these parameters:

ParameterDefaultDescription
sourceDirectory${basedir}/src/main/avroDirectory scanned for Avro definition files
outputDirectory${project.build.directory}/generated-sourcesWhere generated Java is written; added as a compile source root
deleteBaseEventFilestrueRemove the generated base-type classes, since they already ship in jeap-messaging-avro
enableDecimalLogicalTypefalseMap Avro decimal logical types to BigDecimal

Naming conventions

The naming conventions are load-bearing: the plugin adds and validates code based on them (payload records end in Payload, references in References/Reference, keys in MessageKey, values in Event/Command). A schema that violates them fails the build. See Defining messages.