Repository navigation
Getting Started
plugins {
java
id("io.github.malczuuu.modelmaker") version "..."
}The plugin works on its own, but it only wires generated sources into a source set when the java plugin is applied -
which is the normal case.
ModelMaker generates annotations; it does not bring their libraries with it. Add only what the enabled features require:
dependencies {
// jackson feature
implementation(platform("com.fasterxml.jackson:jackson-bom:2.22.2"))
implementation("com.fasterxml.jackson.core:jackson-databind")
// validation feature
implementation("jakarta.validation:jakarta.validation-api:3.1.1")
implementation("org.hibernate.validator:hibernate-validator:9.1.3.Final")
// openApi feature
implementation("io.swagger.core.v3:swagger-annotations-jakarta:2.2.30")
}org.jspecify:jspecify is not on that list - the plugin adds it on compileOnly itself, unless your build already
declares it. See Gradle Plugin.
One type per file, under src/main/model. The file name must be <title>.json:
src/main/model/com.example.dto.Person.json
{
"$modelmaker": "v1.0",
"title": "com.example.dto.Person",
"type": "object",
"required": ["id"],
"properties": {
"id": { "type": "string" },
"age": { "type": "integer", "minimum": 0 }
}
}The full key list is on Schema Format.
Everything is off by default - the bare generator emits a plain immutable POJO with no third-party annotations.
modelmaker {
features {
jackson { enabled = true }
validation { enabled = true }
}
}Per-schema overrides are possible too, see Feature Configuration.
./gradlew build # generation runs as part of compilation
./gradlew generateModel # or run both generators on their owngenerateModelJava runs before compilation and writes:
src/main/model/java/com/example/dto/Person.java
That directory is registered as a source directory of the main source set, so javac picks it up with no extra
configuration.
By default, generated sources are written into the project tree (src/main/model/java), so they are meant to be
reviewed and checked into version control - the diff of a schema change is visible in the generated code.
To keep them out of the tree instead:
modelmaker {
src { enabled = false } // writes build/generated/sources/modelmaker/java/main
}To read the schemas from somewhere else - the generated sources follow them:
modelmaker {
schemas { directory = layout.projectDirectory.dir("src/main/schemas") }
}Either way the directory is wiped and rebuilt on every run of the task - never edit generated files by hand.
A final class with private fields, no setters, a builder, equals / hashCode / toString, and a mutate()
method returning a pre-filled builder. Walk through it on Generated Java Code.
- Schema Format - every key you can write in a schema.
- Validation - which schema keywords become which constraint annotations.
-
Kotlin Extensions - add a
mutate { }DSL for Kotlin callers. - Examples - runnable builds in the repository.
ModelMaker - Apache License 2.0 - Issues - Wiki index
Start here
Schemas
Output
Features
Integration
Reference