spring-bootgradlespringdoc-openapi-ui

Is springdoc-openapi-gradle-plugin compatible with id("org.springframework.boot") version "3.2.5"?


I'm trying to use springdoc-openapi-gradle-plugin to generate OpenAPI documentation on my Spring Boot app. However it does not seem to work.

I've added to application-test.yml:

(...)
oauth:
    killSwitch: true
springdoc:
  swagger-ui:
    enabled: false
  api-docs:
    enabled: true

And to build.gradle:

plugins {
id("org.springframework.boot") version "3.2.5"
(...)
id("org.springdoc.openapi-gradle-plugin") version "1.8.0"
}

dependencies {
(...)
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-starter-test")
(...)
implementation("org.springdoc:springdoc-openapi-ui:1.8.0")
implementation("org.springdoc:springdoc-openapi-kotlin:1.8.0")

}

(...)

tasks.named("forkedSpringBootRun", JavaExecFork::class) {
    classpath = sourceSets["test"].runtimeClasspath
}

openApi {
    apiDocsUrl.set("http://localhost:8080/v3/api-docs.yaml")
    outputDir.set(file("src/main/resources"))
    outputFileName.set("test.swagger")
    waitTimeInSeconds.set(120)

    customBootRun{
        classpath.setFrom(sourceSets["test"].runtimeClasspath)
        mainClass.set("xxx.TestConfiguration")
        args.set(listOf("--spring.profiles.active=test"))
    }
}

tasks.named("generateOpenApiDocs") {
    dependsOn("testClasses")
    mustRunAfter("testClasses")
}

However, after running task generateOpenApiDocs, wait until app is running I got:

(...)
... Tomcat started on port 8080 (http) with context path ''
... Started TestConfiguration.Companion in 10.671 seconds (process running for 10.982)


Execution failed for task ':generateOpenApiDocs'.
> Unable to connect to http://localhost:8080/v3/api-docs.yaml waited for 120 seconds

I wonder if my spring boot version is not compatible or is there anything else missing?

Thanks


Solution

  • Main problem is not with this id("org.springdoc.openapi-gradle-plugin") version "1.8.0" because this is the latest version which is supported by Spring Boot 3

    You have to upgrade openapi dependencies. Few dependencies are older which is not supported by SpringBoot 3.

    implementation("org.springdoc:springdoc-openapi-ui:1.8.0") replace with: implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0")

    For more information visit this page