2

The official docs at https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html only describe how to add the -Dmicronaut.openapi.views.spec=... compiler flag to the JavaCompile Gradle task:

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

This task is not used though in a pure Kotlin project. I already tried tasks.withType(compileKotlin) but without success.

Can anybody give me a hint how to pass the compiler flag in build.gradle (still Groovy) for a pure Kotlin project?

lathspell
  • 3,040
  • 1
  • 30
  • 49
  • please view my answer here https://stackoverflow.com/questions/59261044/micronaut-openapi-swagger-is-not-generating-views/67290338#67290338 – Archmede Apr 27 '21 at 20:38

2 Answers2

1

I believe what you are looking for (at least for Micronaut JVM args for OpenApi) is something like this:

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" for more info generally on how to provide options to the Kotlin Compile step (be sure you're looking at the Groovy Gradle version, as you are not using the Kotlin DSL in your Gradle file)

This SO question seems to be asking a similar thing and may also be useful

I don't think the fork option is available in kotlinOptions (my suspicion is KotlinCompile already runs in a forked process? Not entirely sure there)

Will Buck
  • 1,500
  • 16
  • 25
  • 1
    Thanks, "freeCompilerArgs" was the right thing. My "-D" option still does not work as kotlinc 1.3.61 does not offer a "-D" and "-Xjavac-arguments=" does not work for my example but I ask the Micronaut Devs what exactly they want to archive. – lathspell Dec 10 '19 at 09:07
  • Can you clarify what you mean by "but I ask the Micronaut Devs what exactly they want to archive."? What is it you'd like to see from the Micronaut team here? – Will Buck Dec 11 '19 at 22:42
  • I asked how to pass a compiler flag to kotlinc so the answer was technically correct. It does not make the software work though :-) More on that at https://github.com/micronaut-projects/micronaut-openapi/issues/108 – lathspell Dec 12 '19 at 08:18
0

This one works for me:

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