springdoc / springdoc-openapi-gradle-plugin

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
148 stars 47 forks source link

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" #121

Open matthewadams opened 1 year ago

matthewadams commented 1 year ago

Steps to reproduce:

$ ./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
nbam-e commented 1 year ago

@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.

Leprechaunz commented 1 year ago

I'm having same issue with version 1.7.0.

Looks like there is a workaround. But it's not working for combination of Spring Boot 2.7.14 & Gradle 8.1.1.

matthewadams commented 1 year ago

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! 🙏🏼

vanta commented 1 year ago

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

vlsi commented 7 months ago

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() } }