Repository navigation
Gradle Plugin
io.github.malczuuu.modelmaker is the intended way to use ModelMaker: it registers the modelmaker { } extension, adds
two generation tasks, and wires their output into the main source set.
plugins {
java
id("io.github.malczuuu.modelmaker") version "..."
}The plugin applies nothing by itself. Source-set wiring and the JSpecify dependency happen only once the java
plugin is present; Kotlin extension generation additionally requires org.jetbrains.kotlin.jvm.
modelmaker {
schemas {
directory = layout.projectDirectory.dir("src/main/model") // default
}
src {
enabled = true // default: write into <schemas>/{java,kotlin} (checked in);
} // false writes into build/generated/sources/modelmaker instead
kotlin {
enabled = false // default off
}
features {
jackson { // @JsonCreator / @JsonProperty / ...
enabled = false
annotateFields = false
annotateGetters = true
}
validation { enabled = false } // jakarta.validation annotations, @Valid cascades
openApi { enabled = false } // OpenAPI @Schema (description / example / requiredMode)
withers { enabled = false } // withXyz(value) per property
preferPrimitives { enabled = false } // int/double/boolean instead of boxed types
}
}-
schemas { directory }- defaultsrc/main/model. Where schema files are read from; it need not exist. -
src { enabled }- defaultfalse. Write generated sources into the project tree rather than underbuild/. -
kotlin { enabled }- defaultfalse. Generatemutate { }extensions, see Kotlin Extensions. -
features { }- all off by default. See Feature Configuration.
Schemas live under src/main/model, scanned recursively. One type per file, named <title>.json. Subdirectories
are free to use for grouping - the package comes from title, not from the path.
The directory need not exist: a project that applies the plugin without any schemas builds normally.
src/main/model/ ← schemas
├── com.example.dto.Address.json
└── com.example.dto.Customer.json
build/generated/sources/modelmaker/ ← generated output (the default)
└── java/main/com/example/dto/
├── Address.java
└── Customer.java
With src { enabled = true } the output moves next to the schemas instead, into src/main/model/java.
If the directory holds no schemas - or does not exist - the tasks log No model schemas found in ... and remove
their output directory instead of leaving an empty one behind.
To read schemas from somewhere else:
modelmaker {
schemas { directory = layout.projectDirectory.dir("src/main/schemas") }
}With src.enabled on, the generated sources follow: they are written to <schemas>/java and <schemas>/kotlin.
-
generateModelJava(JavaModelGenerate) - one.javaclass per schema file. -
generateModelKotlin(KotlinModelGenerate) - depends ongenerateModelJava; one<Name>Extensions.ktper type. -
generateModel- a lifecycle task running both of the above. Handy to invoke by hand; the build does not need it, since compilation already depends on the generators through the source set.
Both are in the modelmaker group and run automatically before compilation, because their output directories are
registered as source directories of the main source set.
./gradlew generateModelJava
./gradlew build # runs generation firstThe task exposes the same blocks as the extension, with the extension's values as conventions:
import io.github.malczuuu.modelmaker.gradle.tasks.JavaModelGenerate
tasks.named<JavaModelGenerate>("generateModelJava") {
features {
withers { enabled = true }
}
}This is the middle level of the precedence chain described in Feature Configuration.
src.enabled |
Java | Kotlin |
|---|---|---|
false (default) |
build/generated/sources/modelmaker/java/main |
build/generated/sources/modelmaker/kotlin/main |
true |
<schemas>/java |
<schemas>/kotlin |
Both directories are added to the main source set. javac compiles the .java; the Kotlin plugin, when applied,
compiles the .kt.
With src.enabled = true the generated code is part of the repository - a schema change shows up as a reviewable
diff - and it needs excluding from formatting tools that would otherwise fight the generator:
spotless {
java {
target("src/**/*.java")
targetExclude("build/**", "src/main/model/java/**")
}
}- Not incremental. The output directory is deleted and rebuilt on every run - never hand-edit generated files.
-
Cacheable. Both tasks are
@CacheableTask, with the schema directory as a relative-path-sensitive input and the feature flags as@Inputs. Flip a flag and generation re-runs. -
Configuration-cache compatible. The plugin declares configuration cache support, and the repository itself builds
with
org.gradle.configuration-cache=true. -
generateModelKotlindoubles as a cleaner. When Kotlin generation is off - or the Kotlin plugin is absent - it deletes its output directory instead of leaving stale.ktfiles behind.
Generated classes are @NullMarked, so org.jspecify:jspecify must be on the compile classpath. The plugin adds it on
compileOnly unless the build already declares it in api, compileOnlyApi, compileOnly or implementation.
Declare it yourself when you want a specific version, or when the annotations must be visible at runtime:
dependencies {
implementation("org.jspecify:jspecify:1.0.1")
}plugins {
kotlin("jvm") version "..."
id("io.github.malczuuu.modelmaker") version "..."
}
modelmaker {
kotlin { enabled = true }
}Both conditions must hold - kotlin.enabled = true and the Kotlin JVM plugin applied - or generateModelKotlin
produces nothing. Details on Kotlin Extensions.
The plugin never contributes Jackson, jakarta.validation or swagger annotations. Add whichever the enabled features
need, see Getting Started.
The core generator is a plain library with no build-tool API. See Library Usage.
ModelMaker - Apache License 2.0 - Issues - Wiki index
Start here
Schemas
Output
Features
Integration
Reference