springdoc-openapi-gradle-plugin
springdoc-openapi-gradle-plugin copied to clipboard
Build fails when running the api generation during a publish task.
TLDR: As described here the build fails while running the api generation during a publish task.
Version Information:
Springdoc-openapi-gradle-plugin: 1.7.0 springdoc: 2.1.0 spring-boot: 3.0.6 Gradle: 8.2.1 (using kotlin)
We are using your plugin within our own autoconfigure-gradle-plugin
to apply some default configuration if someone wants to use your plugin to generate the openapi-spec. This works great as long as you only use the generateOpenApiDocs
task directly. But if you hook it into the publish chain (tasks.named("publish").dependsOn("generateOpenApiDocs")
(most likely also when hooking it into the build chain) the whole build fails with something like:
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':skeleton-server:javadocJar' (type 'Jar').
- Gradle detected a problem with the following location: 'C:\cloudflight\src\cloudflight\autoconfigure-gradle-plugin\src\test\fixtures\springdocopenapi\kotlin-springboot-angular\skeleton-server\build\libs\skeleton-server-0.11.2-SNAPSHOT-javadoc.jar'.
Reason: Task ':skeleton-server:forkedSpringBootRun' uses this output of task ':skeleton-server:javadocJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
Possible solutions:
1. Declare task ':skeleton-server:javadocJar' as an input of ':skeleton-server:forkedSpringBootRun'.
2. Declare an explicit dependency on ':skeleton-server:javadocJar' from ':skeleton-server:forkedSpringBootRun' using Task#dependsOn.
3. Declare an explicit dependency on ':skeleton-server:javadocJar' from ':skeleton-server:forkedSpringBootRun' using Task#mustRunAfter.
For more information, please refer to https://docs.gradle.org/8.2/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.
* Try:
> Run with --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
The underlying problem seems to be that the gradle-execfork-plugin
defines the working directory as @InputDirectory
causing Gradle to track all files in the project (also in the build directory) as inputs to the task and therefore failing the build, since the tasks generating these files are not explicitly depended upon.
There already exists a bug report for this here, but nothing happened since March.
I don't know what the best course of action for your plugin would be. I would see 2 options:
- wait for a fix of the mentioned issue.
- replace the plugin with something else? (might not be reasonable)
Things I'm currently trying for our plugin:
- set the working directory for the
forkedSpringBootRun
task to some dummy directory: this seems a bit tricky since the way I'm creating the directory introduces a lot of additional task dependencies for no apparent reason. And its hard to tell which tasks will use a specific directory during configuration time (especially since the user can still change everything) - disable state tracking for the
forkedSpringBootRun
task: this would work, but also disables Gradle task caching for this, which is undesirable since it significantly increases the build time even if not necessary.
If required I can create a demo project for you that illustrates the issue.
@cgrabmann,
Read the docs please: https://springdoc.org/
For spring-boot: 3x use springdoc-openapi
2.x
@bnasslahsen sry I forgot to update that version when I copied it over from another issue.
We are using { module = "org.springdoc:springdoc-openapi-starter-webmvc-api", version = "2.1.0"}
.
I updated the description. Could you please open the issue again.
@cgrabmann,
Please provide the demo project that shows the issue.
@bnasslahsen I created the test repo, you can find it here: https://github.com/cgrabmann/springdoc-issue-120-demo
Running the generateOpenApiDocs
task directly works like a charm.
Running the build
task fails like described.
Seems I was able to get around some of the dependsOn warnings in my plugin with this:
project.extensions.configure(OpenApiExtension::class.java) {
it.customBootRun.workingDir.set(
tasks.named("forkedSpringBootRun").get().temporaryDir
)
}
Seems I was able to get around some of the dependsOn warnings in my plugin with this:
project.extensions.configure(OpenApiExtension::class.java) { it.customBootRun.workingDir.set( tasks.named("forkedSpringBootRun").get().temporaryDir ) }
The workaround here works! It would be better to fix it though.
@bnasslahsen I opened a PR to resolve, please have a look. Thank you https://github.com/springdoc/springdoc-openapi-gradle-plugin/pull/142
I confirm that @hesselapplications's workaround works. I used a simpler configuration:
openApi {
customBootRun {
workingDir = file(layout.buildDirectory).createTempDir()
}
}