joelittlejohn / jsonschema2pojo

Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
http://www.jsonschema2pojo.org
Apache License 2.0
6.22k stars 1.66k forks source link

Multiple jsonschema to individual packages #1594

Open tomasbjerre opened 5 months ago

tomasbjerre commented 5 months ago

I have several schemas and I want each of them to be generated into individual packages.

This code will not work (because the last element in the list will overwrite any previous config...), but perhaps shows what I want to do:

apply plugin: 'jsonschema2pojo'

[
  [
    removeOldOutput: true,
    from: "${rootDir}/src/main/resources/json/sarif-schema.json",
    to: "se.bjurr.violations.lib.model.generated.sarif"
  ],
  [
    removeOldOutput: false,
    from: "${rootDir}/src/main/resources/json/coverity-schema.json",
    to: "se.bjurr.violations.lib.model.generated.coverity"
  ]
].each { codeGen ->
  logger.lifecycle("Generating ${codeGen.from} to ${codeGen.to}")

  jsonSchema2Pojo {
    source = files(codeGen.from)
    targetDirectory = file("src/gen/java")
    targetPackage = codeGen.to
    generateBuilders = true
    annotationStyle = 'none'
    includeGeneratedAnnotation = false
    removeOldOutput = codeGen.removeOldOutput
  }
}