autoconfigure-gradle-plugin icon indicating copy to clipboard operation
autoconfigure-gradle-plugin copied to clipboard

Publishing fails for Open-Api artifacts generated with spring-doc

Open cgrabmann opened this issue 1 year ago • 1 comments

The integration of the org.springdoc:springdoc-openapi-gradle-plugin Plugin runs into a problem while publishing an artifact.

Running the clfGenerateOpenApiDocumentation task and therefore the generateOpenApiDocs task on their own works without issues.

But if the generateOpenApiDocs task is run during publishing it results in an error similar to this:

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.

This happens because the springdoc-openapi-gradle-plugin uses the gradle-execfork-plugin to start the spring-boot application. But the gradle-execfork-plugin declares the working directory as @InputDirectory which causes gradle to track all tasks creating files in the build-directory and then assumes that the forkedSpringBootRun is wrongly configured, since it has those files as input but does not declare a dependency on the generating tasks. This is already tracked in this issue.

As a workaround for now we can disable state tracking for the forkedSpringBootRun task. But this also disables gradle caching and might have undesirable consequences since the job might be run even if it does not need to, resulting in way longer build times then necessary.
We can try to make sure that the open-api documentation generation is only depended on when a publish task is run, but this only solves the issue for projects that do not manage its frontend in the same project. Projects which generate the frontend-api inside the same project will depend on the generated api-spec artifact and therefore run its generation every time the frontend is build.

Another workaround might be to use a dummy working directory for the forkedSpringBootRun task. But this might cause the spring boot application to not start correctly and therefore failing to generate the api-spec completely.

cgrabmann avatar Aug 21 '23 09:08 cgrabmann

for now I implemented a workaround that configures the working directory for the forked spring boot run to be some dummy directory that does not have any content, therefore this error does no longer happen.

But a fix in the plugins themselves would still be preferred.

cgrabmann avatar Aug 22 '23 11:08 cgrabmann