仅使用 Kotlin 时在 Micronaut 中生成 Swagger/OpenAPI 个视图

Generating Swagger/OpenAPI views in Micronaut when using Kotlin only

https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html 的官方文档仅描述了如何将 -Dmicronaut.openapi.views.spec=... 编译器标志添加到 JavaCompile Gradle 任务:

tasks.withType(JavaCompile) {
    options.fork = true
    options.forkOptions.jvmArgs << '-Dmicronaut.openapi.views.spec=rapidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=flattop'
    ...
}

虽然在纯 Kotlin 项目中没有使用此任务。我已经尝试 tasks.withType(compileKotlin) 但没有成功。

谁能告诉我如何在 build.gradle(仍然是 Groovy)中为纯 Kotlin 项目传递编译器标志?

我相信您正在寻找的东西(至少对于 OpenApi 的 Micronaut JVM args)是这样的:

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
    kotlinOptions {
        freeCompilerArgs += '-Dmicronaut.openapi.views.spec=rapidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=flattop'
    }
}

See the Kotlin Docs on "Using Gradle -> Compiler Options" 有关如何为 Kotlin 编译步骤提供选项的更多信息(请确保您正在查看 Groovy Gradle 版本,因为您没有使用Gradle 文件中的 Kotlin DSL)

也可能有用

认为 fork 选项在 kotlinOptions 中可用(我怀疑 KotlinCompile 已经在分叉进程中运行?不完全确定那里)

这个适合我:

kapt {
    arguments {
        arg("micronaut.openapi.views.spec", "redoc.enabled=true,rapidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=flattop")
    }
}