Search code examples
gradlegradle-plugingradle-kotlin-dsl

How to configure jsonschema2pojo plugin on gradle kotlin dsl


I'm using jsonschema2pojo gradle plugin in my kotlin dsl build file.

Now I need to change the default configurations of the plugin as described here

    jsonSchema2Pojo {
      source = files("${sourceSets.main.output.resourcesDir}/json")
    } 

When I add this I get below error -

$ gradle generateJsonSchema2Pojo

Configure project : e: /Users/rajkumar.natarajan/Documents/Coding/misc/jsonschema2pojo-enum-demo/build.gradle.kts:20:1: Unresolved reference: jsonSchema2Pojo e: /Users/rajkumar.natarajan/Documents/Coding/misc/jsonschema2pojo-enum-demo/build.gradle.kts:21:3: Unresolved reference: source e: /Users/rajkumar.natarajan/Documents/Coding/misc/jsonschema2pojo-enum-demo/build.gradle.kts:21:21: Unresolved reference: sourceSets

FAILURE: Build failed with an exception.

  • Where: Build file '/Users/rajkumar.natarajan/Documents/Coding/misc/jsonschema2pojo-enum-demo/build.gradle.kts' line: 20

  • What went wrong: Script compilation errors:

Line 20: jsonSchema2Pojo { ^ Unresolved reference: jsonSchema2Pojo

Line 21: source = files("${sourceSets.main.output.resourcesDir}/json") ^ Unresolved reference: source

Line 21: source = files("${sourceSets.main.output.resourcesDir}/json") ^ Unresolved reference: sourceSets

3 errors

my build file is on github here.

Any idea how to configure my build file for jsonschema2pojo plugin?


Solution

  • try to use this kind of configuration in your gradle.build.kts

    configure <org.jsonschema2pojo.gradle.JsonSchemaExtension> {
        dateTimeType = "java.time.ZonedDateTime"
        includeAdditionalProperties = false
        includeConstructors = true
    
        // etc.
    }