jooby-project / jooby

The modular web framework for Java and Kotlin
https://jooby.io
Apache License 2.0
1.7k stars 199 forks source link

OpenAPI generation issue in multimodule project #3445

Closed IzzzGoy closed 2 months ago

IzzzGoy commented 4 months ago

Task to generate openAPI falls with Application class not found. Did you forget to set `mainClassName`?

But this code works if you pull it into a single-module project.

jooby = 3.1.2 kotlin = 2.0.0

plugins {
    application
    alias(libs.plugins.jvm)
    alias(libs.plugins.kapt)
    alias(libs.plugins.jooby)
    alias(libs.plugins.dependency.management)
    alias(libs.plugins.jooby.openAPI)

    id("com.google.osdetector") version "1.7.3"
    id("com.github.johnrengelman.shadow") version "8.1.1"
}

group  "com.example.app.server.backend"
version = "1.0-SNAPSHOT"

val mainAppClassName = "com.example.app.server.backend.MainKt"

application {
    mainClass = mainAppClassName
}

dependencies {
    testImplementation(kotlin("test"))
    implementation(project(":api:meta"))

    implementation(platform(libs.jooby.bom))
    implementation(libs.bundles.jooby.bom)
    implementation(libs.swagger.annotations)

    kapt("io.jooby:jooby-apt:3.1.2")

    testImplementation("org.jetbrains.kotlin:kotlin-test")
    testImplementation("io.jooby:jooby-test")
    testImplementation("com.squareup.okhttp3:okhttp:4.12.0")

}

tasks.test {
    useJUnitPlatform()
}

kotlin {

    jvmToolchain(17)

    compilerOptions {
        javaParameters = true
    }
}

tasks {

    kapt {

        arguments {
            arg("jooby.incremental", true)
            arg("jooby.services", true)
            arg("jooby.debug", false)
        }
    }
    test {
        useJUnitPlatform()
    }
    shadowJar {
        mergeServiceFiles()
        dependsOn("openAPI")
    }

    joobyRun {
        mainClass = mainAppClassName
        restartExtensions = listOf("conf", "properties", "class")
        compileExtensions = listOf("java", "kt")
        port = 8080

        dependsOn("openAPI")
    }
}
jknack commented 4 months ago

did you try to run from parent/main module?

IzzzGoy commented 4 months ago

did you try to run from parent/main module?

Yes. I moved it to the top of the hierarchy. Set application.mainClass on top of it. Nothing works.

I tried all possible solutions to specify the main class name.

Looks like problem is in multi module system itself.

jknack commented 3 months ago

@IzzzGoy can you share a gradle multiproject example?