user51
user51

Reputation: 10163

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?

Upvotes: 3

Views: 3184

Answers (2)

rchrd
rchrd

Reputation: 389

I've also needed to use jsonschema2pojo plugin. For my use case, I've used this kind of configuration (Kotlin DSL):

jsonSchema2Pojo {
    source.setFrom("src/main/resources/json")
    targetPackage.set("com.example.generated.pojos")
    sourceType.set("jsonschema")

    // Without kotlin dsl
    // source.setFrom files("${project.rootDir}/src/main/resources/json")
    // targetPackage = 'com.example.generated.pojos'
    // sourceType = 'jsonschema'
}

I think that you were interested in source.setFrom. I hope this helps.

Upvotes: 0

pedro_cze
pedro_cze

Reputation: 96

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.
}

Upvotes: 3

Related Questions