Maven
Replace VERSION with the published version shown on the
Maven plugin artifact page.
The plugin requires Java 21. It is built against and tested with Maven 3.9.
For complete, tested builds, see the maven/pom.xml of each
system-test scenario; every scenario is built with this plugin in CI.
Generate Kotlin models
Add the plugin to your pom.xml with one execution for the AsyncAPI document:
<plugin>
<groupId>dev.banking.asyncapi.generator</groupId>
<artifactId>asyncapi-generator-maven-plugin</artifactId>
<version>VERSION</version>
<executions>
<execution>
<id>generate-kotlin-models</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generatorName>kotlin</generatorName>
<inputSpec>${project.basedir}/src/main/resources/asyncapi.yaml</inputSpec>
<modelPackage>com.example.model</modelPackage>
</configuration>
</execution>
</executions>
</plugin>
Run the execution with:
mvn generate-sources
Generated sources are written to target/generated-sources/asyncapi by default;
see Output
directories for the
output path rules. An execution that generates sources registers the output
directory as a compile source root, and one that generates schemas registers its
schema files as resources, so mvn compile and mvn package pick them up
without further configuration. The goal binds to generate-sources by default.
Configure models
Use modelConfig for model settings. For example, this execution generates Java records:
<configuration>
<generatorName>java</generatorName>
<inputSpec>${project.basedir}/src/main/resources/asyncapi.yaml</inputSpec>
<modelPackage>com.example.model</modelPackage>
<modelConfig>
<modelType>java-record</modelType>
</modelConfig>
</configuration>
See Generate Kotlin and Java models for the generated code and its runtime dependencies.
Generate Spring Kafka clients
Set both package fields on the execution and put client settings in clientConfig:
<configuration>
<generatorName>kotlin</generatorName>
<inputSpec>${project.basedir}/src/main/resources/asyncapi.yaml</inputSpec>
<modelPackage>com.example.model</modelPackage>
<clientPackage>com.example.client</clientPackage>
<clientConfig>
<clientType>spring-kafka</clientType>
<clientContract>interface</clientContract>
<producer>
<enabled>true</enabled>
</producer>
<consumer>
<enabled>true</enabled>
</consumer>
</clientConfig>
</configuration>
clientConfig is required when clientPackage is configured, and
modelPackage is required as well. See
Generate Spring Kafka clients for every
client setting.
Share settings across executions
Settings in the plugin-level <configuration> apply to every execution, which
is useful for one clientConfig shared by several contracts. An execution
without clientPackage ignores inherited client settings and prints the
unused-client-config warning. Silence it for executions that intentionally
generate no client:
<plugin>
<groupId>dev.banking.asyncapi.generator</groupId>
<artifactId>asyncapi-generator-maven-plugin</artifactId>
<version>VERSION</version>
<configuration>
<clientConfig>
<clientType>spring-kafka</clientType>
<clientContract>interface</clientContract>
</clientConfig>
</configuration>
<executions>
<execution>
<id>accounts-client</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generatorName>kotlin</generatorName>
<inputSpec>${project.basedir}/src/main/resources/accounts.yaml</inputSpec>
<modelPackage>com.example.accounts.model</modelPackage>
<clientPackage>com.example.accounts.client</clientPackage>
</configuration>
</execution>
<execution>
<id>accounts-avro</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generatorName>avro-schema</generatorName>
<inputSpec>${project.basedir}/src/main/resources/accounts.yaml</inputSpec>
<schemaPackage>com.example.accounts.avro</schemaPackage>
<suppressedWarnings>
<warning>unused-client-config</warning>
</suppressedWarnings>
</configuration>
</execution>
</executions>
</plugin>
suppressedWarnings can also be set at plugin level. See
Configuration warnings
for the rules.
Generate schemas
Select a schema generator profile and set schemaPackage. This example generates Avro schema files without runtime models:
<configuration>
<generatorName>avro-schema</generatorName>
<inputSpec>${project.basedir}/src/main/resources/asyncapi.yaml</inputSpec>
<outputDirectory>${project.build.directory}/generated-schemas/avro</outputDirectory>
<schemaPackage>com.example.schema.avro</schemaPackage>
</configuration>
The schema-only generator profiles are avro-schema, protobuf-schema, and
json-schema. See Generate Avro schemas,
Generate Protobuf schemas and models, and
Generate JSON schemas.
Two executions that write a schema to the same resource path both register
their output directory as a resource root. Maven copies the resources in
order, so the last copy is the one in the build output. Give the executions
distinct schemaPackage values or distinct outputDirectory values so every
schema keeps its own path.
Use a local protoc
Executions with modelType protobuf-message resolve
com.google.protobuf:protoc through the project's repositories; see
Protobuf compiler.
To use a local executable instead, set protocExecutable:
<configuration>
<protocExecutable>/opt/protoc/bin/protoc</protocExecutable>
</configuration>
or pass -Dasyncapi.protocExecutable=/opt/protoc/bin/protoc on the command
line.
Stale generated files
The plugin records the files each execution generates in
target/asyncapi-generator/output-manifest.txt. When a later run of the same
execution no longer generates a file, for example because a schema was removed
from the contract, the file is deleted, unless another execution still
generates it. Files the plugin did not generate are never deleted, and the
bundled outputFile is not managed. See
Stale generated files.
Execution fields
| Field | Description | Default |
|---|---|---|
generatorName |
Generator profile (kotlin, java, avro-schema, protobuf-schema, json-schema, asyncapi-yaml, asyncapi-json) (property asyncapi.generatorName) |
required |
inputSpec |
Path to the AsyncAPI YAML or JSON file (property asyncapi.inputSpec) |
required |
outputDirectory |
Directory for generated sources and schemas (property asyncapi.outputDirectory) |
target/generated-sources/asyncapi |
outputFile |
File for bundled document output (property asyncapi.outputFile) |
none |
modelPackage |
Package for generated payload models (property asyncapi.modelPackage) |
none |
clientPackage |
Package for generated client contracts (property asyncapi.clientPackage) |
none |
schemaPackage |
Package for generated schema artifacts (property asyncapi.schemaPackage) |
none |
modelConfig |
Model implementation and annotation settings | none |
clientConfig |
Spring Kafka client settings | required when clientPackage is configured |
suppressedWarnings |
Configuration warning ids to silence, each in a <warning> element |
none |
protocExecutable |
Local protoc for native Protobuf models (property asyncapi.protocExecutable) |
com.google.protobuf:protoc:3.25.5 from the project repositories |