Generating Quarkus with ZenWave SDK, and building your own customization
zenwave-quarkus generates Java Quarkus from the same ZDL models, using the official ZenWave plugins with a different set of templates. Here is how to use it, and how to build one for your framework.
Generating Quarkus with ZenWave SDK, and building your own customization
ZenWave SDK plugins generate Spring Boot in Java by default. The SDK also ships a Kotlin customization.
Now zenwave-quarkus is a second, unofficial one: it generates Java Quarkus from the same ZDL, OpenAPI and AsyncAPI models.
This quarkus customization is not included in the official plugins delivered by jbang-catalog.json. You need to add them as --deps parameter in the command line, as @import() in .zw scripts or a regular maven dependencies when using the maven plugin.
This post covers:
Using zenwave-quarkus
What it generates
| ZenWave plugin | templates option | Output |
|---|---|---|
BackendApplicationDefaultPlugin | new io.zenwave360.sdk.plugins.quarkus.BackendApplicationQuarkusTemplates | Entities and aggregates, application services, ports, JPA repositories on EntityManager, MapStruct mappers, CDI domain events and listeners, auditing, tests (ArchUnit, in-memory, repository ITs) |
OpenAPIControllersPlugin | new io.zenwave360.sdk.plugins.quarkus.OpenAPIControllersQuarkusTemplates | Jakarta REST (JAX-RS) resources and DTO mappers |
SpringWebTestClientPlugin | new io.zenwave360.sdk.plugins.quarkus.QuarkusHttpTestTemplates | @QuarkusTest HTTP tests, per operation and per business flow |
AsyncAPIGenerator | io.zenwave360.sdk.plugins.quarkus.SmallRyeTemplates | SmallRye Reactive Messaging (Kafka) producers and consumers behind framework-free interfaces |
The generated code is imperative Java (no Uni or Multi in business code), hexagonal (ArchUnit checks that the core does not depend on HTTP or messaging), wired with plain CDI (@ApplicationScoped, constructor injection), and transactional at the application service boundary with jakarta.transaction.Transactional.
Example: a Quarkus modulith from the Arcadia Editions models
The Arcadia Editions sample has six bounded contexts (orders checkout, catalog inventory, catalog products, payments processing, fulfillment shipping, notifications consumer). Their ZDL and OpenAPI models are published in arcadia-editions-modulith-api as a Maven artifact. The same models generate the Java and Kotlin Spring Boot moduliths, and with zenwave-quarkus a Quarkus one.
The whole generation is described in a zenwave-scripts.zw file. @import puts the customization jar and the models jar on the classpath, config holds the usual options, and each plugin block selects the Quarkus templates:
@import("io.zenwave360.sdk:quarkus-backend-application:2.10.0-SNAPSHOT")
@import("com.arcadiaeditions.modulith.application.arcadia-editions-modulith:service-all:0.10.3")
config {
basePackage "com.arcadiaeditions"
layout.commonPackage "{{basePackage}}.common"
// ... other layout.* packages
useJMolecules true
implementEventListeners true
includeEmitEventsImplementation true
persistence jpa
databaseType postgresql
style imperative
plugins {
BackendApplicationDefaultPlugin {
templates "new io.zenwave360.sdk.plugins.quarkus.BackendApplicationQuarkusTemplates"
zdlFile "classpath:/com/arcadiaeditions/modulith/application/arcadia-editions-modulith/orders-checkout-domain-model.zdl"
}
// ... one BackendApplicationDefaultPlugin block per bounded context
OpenAPIControllersPlugin {
templates "new io.zenwave360.sdk.plugins.quarkus.OpenAPIControllersQuarkusTemplates"
zdlFile "classpath:/com/arcadiaeditions/modulith/application/arcadia-editions-modulith/orders-checkout-domain-model.zdl"
openapiFile "classpath:/com/arcadiaeditions/modulith/application/arcadia-editions-modulith/orders-checkout-openapi.yml"
openApiModelNameSuffix DTO
}
SpringWebTestClientPlugin {
templates "new io.zenwave360.sdk.plugins.quarkus.QuarkusHttpTestTemplates"
zdlFile "classpath:/com/arcadiaeditions/modulith/application/arcadia-editions-modulith/orders-checkout-domain-model.zdl"
openapiFile "classpath:/com/arcadiaeditions/modulith/application/arcadia-editions-modulith/orders-checkout-openapi.yml"
openApiModelNameSuffix DTO
}
}
}
Run each plugin block from the CLI with jbang zw, passing both jars with --deps:
DEPS=io.zenwave360.sdk:quarkus-backend-application:2.10.0-SNAPSHOT,com.arcadiaeditions.modulith.application.arcadia-editions-modulith:service-all:0.10.3
CP=classpath:/com/arcadiaeditions/modulith/application/arcadia-editions-modulith
jbang zw -p BackendApplicationDefaultPlugin --deps $DEPS \
"templates=new io.zenwave360.sdk.plugins.quarkus.BackendApplicationQuarkusTemplates" \
zdlFile=$CP/orders-checkout-domain-model.zdl \
basePackage=com.arcadiaeditions \
persistence=jpa databaseType=postgresql style=imperative \
implementEventListeners=true includeEmitEventsImplementation=true
You can regenerate after changing the model. Files that follow the model, such as entities and DTOs, are rewritten. Files where you write code, such as service implementations, mappers and tests, are kept. Add -f to overwrite those too.
In this modulith the bounded contexts talk through in-process CDI events, with no Kafka. A @listener in the ZDL becomes an @Observes(during = AFTER_SUCCESS) method with @Transactional(REQUIRES_NEW): it runs after the publishing transaction commits and never on rollback. That is the Quarkus counterpart of Spring Modulith’s @ApplicationModuleListener, without an event publication registry.
With the Maven plugin
You can also run the same plugins from zenwave-sdk-maven-plugin. Add the customization jar as a plugin dependency, next to the official plugin it customizes:
<plugin>
<groupId>io.zenwave360.sdk</groupId>
<artifactId>zenwave-sdk-maven-plugin</artifactId>
<version>${zenwave.version}</version>
<executions>
<execution>
<id>backend-application</id>
<phase>initialize</phase>
<goals><goal>generate</goal></goals>
<configuration>
<generatorName>BackendApplicationDefaultPlugin</generatorName>
<inputSpec>zenwave-model.zdl</inputSpec>
<targetFolder>${project.basedir}</targetFolder>
<configOptions>
<templates>new io.zenwave360.sdk.plugins.quarkus.BackendApplicationQuarkusTemplates</templates>
<basePackage>io.example.orders</basePackage>
<persistence>jpa</persistence>
<databaseType>postgresql</databaseType>
<style>imperative</style>
</configOptions>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>io.zenwave360.sdk.plugins</groupId>
<artifactId>backend-application-default</artifactId>
<version>${zenwave.version}</version>
</dependency>
<dependency>
<groupId>io.zenwave360.sdk</groupId>
<artifactId>quarkus-backend-application</artifactId>
<version>${zenwave-quarkus.version}</version>
</dependency>
</dependencies>
</plugin>
For AsyncAPI, use AsyncAPIGenerator with templates set to io.zenwave360.sdk.plugins.quarkus.SmallRyeTemplates and the io.zenwave360.sdk:asyncapi-quarkus jar. The zenwave-quarkus README has the full configuration.
Things to know
- The project must exist. The templates write sources into an existing Quarkus project. They do not create the
pom.xmlorapplication.properties. Start fromquarkus createand add MapStruct, Flyway and the test dependencies. docs/e2e-scaffold.md lists every change. - Snapshots only for now. zenwave-quarkus is published to
https://www.zenwave360.io/maven-snapshots/, not to Maven Central. Add it as a repository and as a plugin repository, ormvn installthe project locally. - Kafka. Producers use
Emitter<String>and send after the JTA transaction commits. Consumers use@Incoming+@Blockingand send failed messages to a dead-letter topic. There is no outbox yet. - Hand-written parts. Business decisions the model cannot express are marked
// TODO CUSTOM_REQUIRED, for example which target state a multi-target@transitiontakes. This works the same as the official plugins.
Building your own customization
zenwave-quarkus has the same shape as the SDK’s Kotlin module, and that shape works for Micronaut, Helidon, a different persistence stack, or your company’s in-house conventions. A customization jar has three parts:
- Handlebars templates (
.hbs), one per generated file. - One Templates class per plugin, which lists the templates to render, where to write them, and when to skip them.
- Helper classes, Java methods the templates call to compute types, signatures and names.
Project layout
my-customization/
├── pom.xml
└── src/
├── main/java/com/example/zenwave/
│ ├── BackendApplicationMyTemplates.java
│ └── BackendApplicationMyHelpers.java
├── main/resources/com/example/zenwave/BackendApplicationDefaultGenerator/
│ └── src/main/java/core/... # .hbs templates
└── test/java/... # runs the official plugin with your templates
Depend on the official plugins with provided scope, so the jar carries only your classes and templates:
<dependency>
<groupId>io.zenwave360.sdk.plugins</groupId>
<artifactId>backend-application-default</artifactId>
<version>${zenwave.version}</version>
<scope>provided</scope>
</dependency>
The Templates class
The Templates class extends the plugin’s own (ProjectTemplates for the backend plugin), points to your templates folder, and registers each template in a list. The list decides how many times a template runs and what model it gets:
| List | Runs | Model | Typical output |
|---|---|---|---|
entityTemplates | once per entity | entity | JPA entity, repository, repository test, test data |
aggregateTemplates | once per aggregate | aggregate | aggregate class and its transitions |
enumTemplates, inputTemplates, outputTemplates | once per enum, input or output | enum / entity | enums and DTOs |
serviceTemplates | once per service | service | service interface, implementation, mapper, tests |
domainEventsTemplates | once per event | event | domain event classes |
listenersByApiTemplates | once per group of @listener bindings | listenerGroup | event listeners and their mappers |
allEntitiesTemplates, allServicesTemplates, … | once, with every item of that kind | all entities, all services, … | files that wire them all, such as the in-memory test config of every service |
singleTemplates | once per run | the whole zdl | shared base classes: BaseMapper, auditing, ArchUnit test |
Each entry gives the template path, the output package and file name, the output format, an optional skip function, and a skipOverwrite flag. With skipOverwrite set to false, the file is regenerated on every run, so it always follows the model: entities, enums, DTOs, service interfaces. With true, the file is written once and then left alone, because it is where you add your own code: service implementations, mappers, listeners and tests. Only forceOverwrite (-f in the CLI) replaces those.
public class BackendApplicationQuarkusTemplates extends ProjectTemplates {
// Plugin options are bound onto public fields with the same name
public PersistenceType persistence = PersistenceType.jpa;
protected Function<Map<String, Object>, Boolean> skipEntity = (model) -> is(model, "vo", "input");
public BackendApplicationQuarkusTemplates() {
setTemplatesFolder("io/zenwave360/sdk/plugins/quarkus/BackendApplicationDefaultGenerator");
var layoutNames = new ProjectLayout();
this.addTemplate(this.entityTemplates, "src/main/java", "core/domain/{{persistence}}/Entity.java",
layoutNames.entitiesPackage, "{{entity.name}}.java", JAVA, skipEntity, false);
this.addTemplate(this.serviceTemplates, "src/main/java", "core/implementation/{{style}}/ServiceImpl.java",
layoutNames.coreImplementationPackage, "{{service.name}}Impl.java", JAVA, null, true);
// ...
}
@Override
public List<Object> getTemplateHelpers(Generator generator) {
var helpers = new ArrayList<>(super.getTemplateHelpers(generator));
helpers.add(new BackendApplicationQuarkusHelpers((BackendApplicationDefaultGenerator) generator));
return helpers;
}
}
Users select it with templates "new com.example.zenwave.BackendApplicationMyTemplates". Leaving a template out of the lists is how you drop output you don’t want, such as the Spring-only or MongoDB files.
Helpers and templates
How you get your first set of templates depends on how far your target is from Spring Boot:
- Java, with code and architecture close to the Spring Boot output (Quarkus, Micronaut, Helidon): copy the official templates of each plugin into your folder, then edit them. That is how zenwave-quarkus started. Copy all of them, even the ones you don’t change yet: the generated output stays in one place you can read, and an SDK release can’t change your output behind your back. The price is porting upstream fixes by hand.
- A different framework, or a different language such as Node.js or .NET: write, or pick, a small playground project that follows the architecture you want. Then point a coding agent at that project and at the official templates, and ask it to write the templates for your target. The official templates show which model keys and helpers are available and what each file is for. The playground shows what the output should look like.
Helpers add scripting to the .hbs templates: Java code for what is awkward in Handlebars, such as computing a type, a method signature or a name. The official plugins already register many of them (wrapWithMapper, isCrudMethod, mapperInputCallSignature, …). Reuse them as long as they fit your target language and framework. Add your own as plain public methods that take the model (Map) and Handlebars Options. A helper with the same name as an official one replaces it. zenwave-quarkus does this to override javaType and methodParametersSignature. For a non-Java target, expect to replace most of the type and signature helpers.
Tests
Test the jar by running the official plugin with your templates on a small model, then checking the generated files:
Plugin plugin = new BackendApplicationDefaultPlugin()
.withZdlFile("classpath:zdl/customer-address-relational.zdl")
.withTargetFolder("target/orders")
.withOption("templates", "new " + BackendApplicationQuarkusTemplates.class.getName())
.withOption("basePackage", "io.example.orders")
.withOption("forceOverwrite", true);
new MainGenerator().generate(plugin);
String serviceImpl = Files.readString(root.resolve("core/application/CustomerServiceImpl.java"));
assertTrue(serviceImpl.contains("jakarta.transaction.Transactional"));
assertFalse(serviceImpl.contains("org.springframework"));
Unit tests catch a missing helper. They won’t tell you whether the output compiles and runs. For that, zenwave-quarkus has an e2e module that generates two real Quarkus projects, builds them, and runs their tests against Dev Services. Keep the e2e models broad, because Handlebars renders a missing model key as blank instead of failing.
Know what you depend on
The templates option is the only documented extension point. Template lists, helper names, model keys and utility classes are SDK internals and can change between releases. Pin the SDK version, and diff the upstream templates when you bump it. zenwave-quarkus keeps that list, and its bump checklist, in docs/sdk-coupling.md.
Links
- zenwave-quarkus: the Quarkus customization
- Kotlin customization: the official one, same shape
- arcadia-editions-modulith-api: the Arcadia Editions models used above
- Customizing Generated Code: the other customization options in ZenWave SDK