Gradle plugin that generates code from handlebars template.

1. Applying The Plugin

plugins {
    id("io.samjingwen.code-generator")
}

2. Configure Source, Output And Template File

generateCode {
    templateFile.set("$projectDir/src/main/resources/templates/example.hbs")
    sourceFile.set("$projectDir/src/main/resources/source.yaml")
    outputFile.set("$buildDir/generated/codegen/HttpStatus.java")
}

3. Add Output Directory To Source Sets

sourceSets {
    main {
        java {
            srcDir("$buildDir/generated/codegen")
        }
    }
}

4. Auto Generate Before Java Compilation

tasks.withType<JavaCompile> {
    dependsOn(tasks.withType(io.samjingwen.codegenerator.CodeGenerationTask::class.java))
}

5. Complete Example

See complete working example here.

6. Source Code