Skip to content

Commit

Permalink
Remove workaround for #171 because cause was fixed in springdoc-opena…
Browse files Browse the repository at this point in the history
…pi-plugin

Signed-off-by: Rick Spiegl <rick.spiegl@cloudflight.io>
  • Loading branch information
rspiegl committed Jun 25, 2024
1 parent f54871e commit 254b08b
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 58 deletions.
23 changes: 1 addition & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,28 +478,7 @@ plugins {
}
```

The plugin has to be applied to a module that provides a Spring Boot application which the plugin will try to start using a custom Spring Boot run configuration.
This custom run configuration will be started in a dummy working directory to work around a issue currently present in the springdoc plugin. You can find more information [here](https://github.com/cloudflightio/autoconfigure-gradle-plugin/issues/171).
The dummy working directory is created with a task called `createDummyForkedSpringBootWorkingDir`. Various other tasks are automatically configured to depend on this, since they access the dummy directory for some reason.

<details>
<summary>If you run into some problems with the task, try adding it as a dependency to your task by adding the following.</summary>

```groovy
tasks.named("your-task-name") {
dependsOn("createDummyForkedSpringBootWorkingDir")
}
```

If you have multiple tasks that need to depend on it you can do:

```groovy
def taskList = ["your-task-1", "your-task-2"]
tasks.matching { taskList.contains(it.name) }.all {
dependsOn("createDummyForkedSpringBootWorkingDir")
}
```
</details>
The plugin has to be applied to a module that provides a Spring Boot application which the plugin will try to start using a custom Spring Boot run configuration.

The springdoc plugin is automatically configured to generate the open-api spec in `YAML` format. If you prefer the `JSON` format you can easily change that by using our extension:
```groovy
Expand Down
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ dependencies {

implementation(libs.springdoc.openapi.plugin)
implementation(libs.kotlinx.serialization.json)
implementation(libs.exec.fork.plugin)

testImplementation(libs.bundles.testImplementationDependencies)

Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ swagger-codegen-plugin = { module = "gradle.plugin.org.hidetake:gradle-swagger-g
swagger-jersey2-jaxrs = { module = "io.swagger:swagger-jersey2-jaxrs", version = { strictly = "1.6.2" } }

springdoc-openapi-plugin = { module = "org.springdoc:springdoc-openapi-gradle-plugin", version = "1.9.0" }
exec-fork-plugin = { module = "com.github.psxpaul:gradle-execfork-plugin", version = "0.2.0" }

junit-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "jupiter" }
junit-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "jupiter" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.cloudflight.gradle.autoconfigure.springdoc.openapi

import com.github.psxpaul.task.JavaExecFork
import io.cloudflight.gradle.autoconfigure.AutoConfigureGradlePlugin.Companion.TASK_GROUP
import io.cloudflight.gradle.autoconfigure.extentions.gradle.api.tasks.named
import io.cloudflight.gradle.autoconfigure.extentions.gradle.api.tasks.withType
Expand All @@ -18,7 +17,6 @@ import org.springdoc.openapi.gradle.plugin.OpenApiGeneratorTask
import org.springdoc.openapi.gradle.plugin.OpenApiGradlePlugin
import org.springframework.boot.gradle.plugin.SpringBootPlugin
import java.net.ServerSocket
import java.nio.file.Files

class SpringDocOpenApiConfigurePlugin : Plugin<Project> {
override fun apply(target: Project) {
Expand All @@ -42,40 +40,11 @@ class SpringDocOpenApiConfigurePlugin : Plugin<Project> {
it.dependsOn(documentationTask)
}

`setupWorkaroundFor#171`(target, openapi)

target.afterEvaluate {
configureDocumentPublishing(openapi, target, openApiTask)
}
}

private fun `setupWorkaroundFor#171`(target: Project, openapi: OpenApiExtension) {
val forkedSpringBootRun = target.tasks.named("forkedSpringBootRun", JavaExecFork::class)

val createDirTask = target.tasks.register("createDummyForkedSpringBootWorkingDir") { task ->
// use same working dir resolution as plugin itself: https://github.com/springdoc/springdoc-openapi-gradle-plugin/blob/master/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePlugin.kt#L98
val workingDirProvider = openapi.customBootRun.workingDir.zip(forkedSpringBootRun) { dir, forked ->
dir?.asFile ?: forked.workingDir
}
task.outputs.dir(workingDirProvider)
task.doFirst {
val workingDir = workingDirProvider.get()
Files.createDirectories(workingDir.toPath())
}
}

// these tasks also need to depend on the createDirTask since they somehow access the dummy folder as well
val dependingTaskNames = setOf("resolveMainClassName", "processResources", "compileKotlin", "compileJava")

target.tasks.matching { dependingTaskNames.contains(it.name) }.all {
it.dependsOn(createDirTask)
}

forkedSpringBootRun.configure {
it.dependsOn(createDirTask)
}
}

private fun configureOpenApiExtension(
openapi: OpenApiExtension,
configureExtension: SpringDocOpenApiConfigureExtension,
Expand Down Expand Up @@ -104,9 +73,6 @@ class SpringDocOpenApiConfigurePlugin : Plugin<Project> {
openapi.outputDir.set(target.layout.buildDirectory.dir("generated/resources/openapi"))
openapi.outputFileName.set(outputFileName)
openapi.apiDocsUrl.set(docsUrl)
openapi.customBootRun {
it.workingDir.set(target.layout.buildDirectory.dir("dummyForkedSpringBootWorkingDir"))
}

mapOf(
"--server.port" to serverPort,
Expand Down

0 comments on commit 254b08b

Please sign in to comment.