springdoc-openapi-gradle-plugin
springdoc-openapi-gradle-plugin copied to clipboard
Gradle plugin 1.7.0 fails with latest Spring Boot 3.1.2, Gradle Kotlin 8.3 with "Task with name 'bootRun' not found in root project"
Steps to reproduce:
-
Generate a new Gradle Kotlin Spring Boot project (see settings below) from start.spring.io
-
Update gradle to 8.3 in
gradle/wrapper/gradle-wrapper.properties
:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
- Add the springdoc plugin to the project:
...
plugins {
id("org.springframework.boot") version "3.1.2"
id("io.spring.dependency-management") version "1.1.2"
id("org.springdoc.openapi-gradle-plugin") version "1.7.0" // <-- added
kotlin("jvm") version "1.8.22"
kotlin("plugin.spring") version "1.8.22"
}
...
- Issue command
./gradlew generateOpenApiDocs
, observe failure
$ ./gradlew generateOpenApiDocs
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/matthewadams/Downloads/demo/build.gradle.kts' line: 3
* What went wrong:
An exception occurred applying plugin request [id: 'org.springdoc.openapi-gradle-plugin', version: '1.7.0']
> Failed to apply plugin 'org.springdoc.openapi-gradle-plugin'.
> Task with name 'bootRun' not found in root project 'demo'.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 307ms
@matthewadams I had the same issue with bootRun not found after upgrading.
In our case our plugins section looked like this:
plugins {
id 'org.springframework.boot' version '2.7.14'
id 'org.springdoc.openapi-gradle-plugin' version '1.7.0'
id 'java'
}
The issue went away when reordering this to
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.14'
id 'org.springdoc.openapi-gradle-plugin' version '1.7.0'
}
So maybe try with kotlin before springboot?
It seems that the openapi plugin now depends on a particular initialization order whereas previously (before 1.7.0) it did not matter. If this behavior change is intentional, it should probably be documented somewhere.
I'm having same issue with version 1.7.0.
- First project (Spring Boot 3.1.2, Gradle 8.1.1) was fixed by adding
id("application")
as first plugin. @nbam-e 's idea about moving Kotlin before Spring Boot also worked for me. - Second project (Spring Boot 2.7.14, Gradle 7.6.1) was fixed with same way as first project (by adding
id("application")
). - Third project (Spring Boot 2.7.14, Gradle 8.1.1) didn't work at all.
Looks like there is a workaround. But it's not working for combination of Spring Boot 2.7.14 & Gradle 8.1.1.
Sure enough, reording like this got rid of the problem:
plugins {
kotlin("jvm") version "1.8.22"
kotlin("plugin.spring") version "1.8.22"
id("org.springframework.boot") version "3.1.2"
id("org.springdoc.openapi-gradle-plugin") version "1.7.0"
id("io.spring.dependency-management") version "1.1.2"
}
This either needs to be identified as a bug and fixed, or at least documented.
Thanks! 🙏🏼
Any update here? Gradle 8
is out for some time, same for SpringBoot 3
, and looks like it's not easy to work with them using springdoc
I guess the fix (at springdoc-openapi-gradle-plugin
side) is
a) Either stop using bootRun
task directly (e.g. here https://github.com/springdoc/springdoc-openapi-gradle-plugin/blob/e855f9c3aeb776f3d3ef285c80aca748c5a50950/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePlugin.kt#L31-L32). Is the task really helpful?
b) Wait for both org.springframework.boot
and java
plugins, and massage bootRun
only in case both plugins are added (see https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#reacting-to-other-plugins.java ). For instance: plugins.withId("org.springframework.boot") { plugins.withId("java") { massageBootRunTask() } }