Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails when running the api generation during a publish task. #120

Closed
cgrabmann opened this issue Aug 21, 2023 · 8 comments · Fixed by #142
Closed

Build fails when running the api generation during a publish task. #120

cgrabmann opened this issue Aug 21, 2023 · 8 comments · Fixed by #142
Labels
invalid This doesn't seem right

Comments

@cgrabmann
Copy link
Contributor

cgrabmann commented Aug 21, 2023

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.

@bnasslahsen
Copy link
Contributor

@cgrabmann,

Read the docs please:
https://springdoc.org/

For spring-boot: 3x use springdoc-openapi 2.x

@bnasslahsen bnasslahsen added the invalid This doesn't seem right label Aug 21, 2023
@cgrabmann
Copy link
Contributor Author

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

@bnasslahsen
Copy link
Contributor

@cgrabmann,

Please provide the demo project that shows the issue.

cgrabmann added a commit to cgrabmann/springdoc-issue-120-demo that referenced this issue Aug 21, 2023
cgrabmann added a commit to cgrabmann/springdoc-issue-120-demo that referenced this issue Aug 21, 2023
@cgrabmann
Copy link
Contributor Author

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

@bnasslahsen bnasslahsen reopened this Aug 21, 2023
@hesselapplications
Copy link
Contributor

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

@zhahaoyu
Copy link

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.

@hesselapplications
Copy link
Contributor

hesselapplications commented Mar 28, 2024

@bnasslahsen I opened a PR to resolve, please have a look. Thank you
#142

@hosamaly
Copy link

I confirm that @hesselapplications's workaround works. I used a simpler configuration:

openApi {
  customBootRun {
    workingDir = file(layout.buildDirectory).createTempDir()
  }
}

bnasslahsen added a commit that referenced this issue Jun 22, 2024
Issue #120 fix - set fork working dir to temp dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants