Search code examples
kotlingradlebuild.gradleopenapi-generator

Unresolved reference when using openApiGenerate build.gradle.kts


I'm trying to get openapigenerator to help get responses automatically from a swagger for my mocked api. the build.gradle.kts looks like this

buildscript {
    repositories {
        mavenLocal()
        maven("http://repo1.maven.org/maven2")
    }
    dependencies {
        classpath("org.openapitools:openapi-generator-gradle-plugin:6.3.0")
    }
}

plugins {
    id("org.openapi.generator") version "6.3.0"
}

apply(plugin = "org.openapi.generator")

openApiGenerate {
        generatorName = "java"
        inputSpec = "$rootDir/path/to/openapi.yaml".toString()
        outputDir = "$buildDir/generated".toString()
    }

I reload my gradle and can see it downloading openapi but it keeps saying "Unresolved reference" for openApiGenerate and all the variables inside.I'm new to kotlin and gradle any help would be appreciated


Solution

  • openApiGenerate is a task therefore you must use tasks to configure it. You appear to be mixing Groovy syntax with Kotlin, review Gradle Kotlin DSL Primer.

    Additionally, you are mixing the plugins DSL and legacy plugin application. The plugins DSL is the preferred way to apply plugins.

    plugins {
        id("org.openapi.generator") version "6.3.0"
    }
    
    tasks.openApiGenerate {
        generatorName.set("java")
        // and so on, let your IDE assist you.
    }