Skip to content

Development

Damian Malczewski edited this page Sep 10, 2026 · 1 revision

Development

Notes for working on ModelMaker itself. For using it, start at Getting Started.

Commands

./gradlew                                  # default tasks: spotlessApply build publishToMavenLocal
./gradlew build                            # compile + tests + static analysis
./gradlew spotlessApply                    # format and apply the license header
./gradlew :modelmaker:test                 # core unit tests only
./gradlew :modelmaker-gradle-plugin:test   # plugin functional tests (GradleTestKit) only
./gradlew publishToMavenLocal              # publish to ~/.m2, needed before building the examples

Modules

  • :modelmaker - the core generator library. Build-tool-agnostic, has a module-info.java, published as io.github.malczuuu:modelmaker.
  • :plugin-gradle - the Gradle plugin io.github.malczuuu.modelmaker, published as modelmaker-gradle-plugin. Wraps the core in the Gradle API.
  • build-logic/ - an included build holding the shared convention plugins.
  • examples/ - standalone consumer builds, not part of the root build.

Toolchain

  • Java 25 toolchain; main compiles with --release 17 for consumer compatibility, while a modern javac drives ErrorProne and NullAway.
  • NullAway runs in JSpecify mode on main only - a nullness violation fails build.
  • :plugin-gradle uses explicitApi(): every public declaration needs an explicit visibility modifier and return type.

How generation works

schema files → SchemaLoader → ModelType tree → ModelMaker.emit(type) → source text
  • Loading dispatches by file extension. $ref resolution happens across the whole batch after parsing, in SchemaReferences.
  • ModelType is the resolved model - a top-level type plus nested types for inline objects, carrying the per-file FeatureOverrides.
  • ModelMaker has two implementations: JavaModelMaker (the DTO) and KotlinExtensionMaker (the <Name>Extensions.kt). Java output is assembled from small focused *SnippetRenderer pieces - fields, constructor, getters, builder, withers, support methods - each returning its code plus the imports it needs.
  • Feature resolution happens in emit: the schema's own FeatureOverrides are applied on top of the ModelOptions the maker was constructed with.

Plugin internals

ModelMakerPlugin registers the modelmaker { } extension and two tasks, generateModelJava and generateModelKotlin (which depends on it). Under the java plugin it puts both output directories on the main source set and adds org.jspecify:jspecify on compileOnly unless already declared.

Tasks are @CacheableTask but deliberately not incremental - the output directory is wiped and rebuilt on every run. generateModelKotlin doubles as a cleaner: with Kotlin generation off it deletes its output directory rather than leaving stale .kt files.

Conventions

  • Spotless enforces the license header (gradle/license-header.txt) on every *.java / *.kt / *.kts under src/, google-java-format for Java, ktfmt for Kotlin sources and ktlint for *.gradle.kts.
  • No wildcard imports in Java.
  • Tests run with the per_class lifecycle - use proper @BeforeEach / @AfterEach, or @BeforeAll on an instance method.
  • Plugin tests are functional tests driven through GradleTestKit.

Testing a change end to end

./gradlew publishToMavenLocal
examples/buildAll build

The examples check in their generated sources, so a change in the emitted code shows up as a diff under examples/*/src/main/model/java. Review it - that diff is the most readable description of what your change does. See Examples.

Documentation

  • README.md stays short: what the project is, and one trivial example.
  • Everything else belongs in this wiki. When behavior changes, update the page that describes it and, if a new page is added, list it in _Sidebar.md and on Home.

Clone this wiki locally