springdoc-openapi-gradle-plugin钩子在Gradle中构建任务后生成文档

cngwdvgl  于 2023-10-19  发布在  Spring
关注(0)|答案(1)|浏览(126)

我想有openapi文件在构建时生成。
当我将generateOpenApiDocs配置为在build之后运行时:

tasks.named("build") {
    finalizedBy("generateOpenApiDocs")
}

我得到以下错误:

Some problems were found with the configuration of task ':forkedSpringBootRun' (type 'JavaExecFork').
  - Gradle detected a problem with the following location: '/Users/user/projects/service/build/classes/java/aot'.
    
    Reason: Task ':forkedSpringBootRun' uses this output of task ':compileAotJava' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

我尝试了forkedSpringBootRun/doNotTrackState,但它不适合我-我仍然得到之前提到的错误。
Repository with reproduction - https://github.com/kkocel/openapigradlerepro

hc2pp10m

hc2pp10m1#

TL;DR;

在构建脚本中额外配置forkedSpringBootRun

tasks {
  forkedSpringBootRun {
    doNotTrackState("See https://github.com/springdoc/springdoc-openapi-gradle-plugin/issues/102")
  }
}

如果Gradle构建之后仍然失败并显示相同的消息,则必须在forkedSpringBootRun中定义dependsOn()中的所有第一级依赖任务,例如:

tasks {
    forkedSpringBootRun {
        dependsOn(
            project.tasks.named("distTar"),
            project.tasks.named("test"),
            ..
        )
    }
}

已知问题

项目本身仍然有关于任务从另一个任务的输出访问文件的问题的公开问题,而另一个任务并不直接依赖于它。
项目中报告的问题:https://github.com/springdoc/springdoc-openapi-gradle-plugin/issues/128
后果
记住,这只是一个解决方案,直到插件正确声明任务依赖关系。因此,此任务不会得到优化,并且可能会稍微影响您的构建性能。阅读更多关于untracked tasks

相关问题