From 5c6d680525585f87e0e6800931898bfa77373f11 Mon Sep 17 00:00:00 2001 From: Vasily Pelikh <2010720+vpelikh@users.noreply.github.com> Date: Fri, 28 Aug 2026 11:53:35 +0300 Subject: [PATCH] Fix Gradle plugin release build: pass springdoc version via system property The functional tests hardcoded a 5.1.0-SNAPSHOT dependency on the springdoc starter artifacts. During a release, prepare-release-commit.sh rewrites gradle.properties to the release version (e.g. 5.1.0) and Maven installs that release version into the local repo, so the sample apps could not resolve the -SNAPSHOT coordinate and the Gradle :test task failed the release build. Pass the plugin project's resolved version to the tests via the springdocVersion system property (set in build.gradle from project.version) and interpolate it into the sample build.gradle dependency coordinates, falling back to 5.1.0-SNAPSHOT for local development. This keeps the tests in sync for both snapshots and releases. --- springdoc-openapi-gradle-plugin/build.gradle | 4 + ...gDocOpenApiGradlePluginFunctionalTest.java | 157 +++++++----------- 2 files changed, 65 insertions(+), 96 deletions(-) diff --git a/springdoc-openapi-gradle-plugin/build.gradle b/springdoc-openapi-gradle-plugin/build.gradle index c21fc0c75..0f983b617 100644 --- a/springdoc-openapi-gradle-plugin/build.gradle +++ b/springdoc-openapi-gradle-plugin/build.gradle @@ -85,4 +85,8 @@ publishing { test { useJUnitPlatform() + // Expose the resolved project version so the functional tests depend on the + // artifacts that were actually built/installed (e.g. 5.1.0 at release time, + // 5.1.0-SNAPSHOT during development) instead of a hardcoded version. + systemProperty 'springdocVersion', project.version } \ No newline at end of file diff --git a/springdoc-openapi-gradle-plugin/src/test/java/org/springdoc/gradle/SpringDocOpenApiGradlePluginFunctionalTest.java b/springdoc-openapi-gradle-plugin/src/test/java/org/springdoc/gradle/SpringDocOpenApiGradlePluginFunctionalTest.java index 2a7dd4c9d..955d76f60 100644 --- a/springdoc-openapi-gradle-plugin/src/test/java/org/springdoc/gradle/SpringDocOpenApiGradlePluginFunctionalTest.java +++ b/springdoc-openapi-gradle-plugin/src/test/java/org/springdoc/gradle/SpringDocOpenApiGradlePluginFunctionalTest.java @@ -2,11 +2,9 @@ import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.GradleRunner; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -21,40 +19,23 @@ class SpringDocOpenApiGradlePluginFunctionalTest { @TempDir Path testProjectDir; - private Path sampleApp; - - @BeforeEach - void setUp() throws IOException { - sampleApp = Paths.get("src/test/resources/sample-app-webflux"); - } + // Resolved version of the springdoc artifacts that were actually built/installed + // (e.g. 5.1.0 at release time, 5.1.0-SNAPSHOT during development). Passed in via the + // springdocVersion system property by build.gradle, falling back to the snapshot for + // local development. + private static final String SPRINGDOC_VERSION = + System.getProperty("springdocVersion", "5.1.0-SNAPSHOT"); @Test void generatesOpenApiSpecFromReactiveApp() throws IOException { - // Copy sample app into the temp project + Path sampleApp = Paths.get("src/test/resources/sample-app-webflux"); copyRecursively(sampleApp, testProjectDir); - // Add settings + build for the sample app, using the plugin under test Files.writeString(testProjectDir.resolve("settings.gradle"), "rootProject.name = 'sample-app-webflux'\n"); - Files.writeString(testProjectDir.resolve("build.gradle"), """ - plugins { - id 'java' - id 'io.github.vpelikh.springdoc-openapi-gradle-plugin' - } - - repositories { - mavenLocal() - mavenCentral() - } - - dependencies { - implementation 'org.springframework.boot:spring-boot-starter-webflux:4.1.1' - implementation 'io.github.vpelikh:springdoc-openapi-starter-webflux-api:5.1.0-SNAPSHOT' - } - - openApiGenerate { - mainClass = 'test.SampleApp' - } - """); + Files.writeString(testProjectDir.resolve("build.gradle"), + buildGradle("webflux", """ + mainClass = 'test.SampleApp' + """)); BuildResult result = GradleRunner.create() .withProjectDir(testProjectDir.toFile()) @@ -75,29 +56,13 @@ void generatesOpenApiSpecFromServletApp() throws IOException { copyRecursively(Paths.get("src/test/resources/sample-app-webmvc"), testProjectDir); Files.writeString(testProjectDir.resolve("settings.gradle"), "rootProject.name = 'sample-app-webmvc'\n"); - Files.writeString(testProjectDir.resolve("build.gradle"), """ - plugins { - id 'java' - id 'io.github.vpelikh.springdoc-openapi-gradle-plugin' - } - - repositories { - mavenLocal() - mavenCentral() - } - - dependencies { - implementation 'org.springframework.boot:spring-boot-starter-web:4.1.1' - implementation 'io.github.vpelikh:springdoc-openapi-starter-webmvc-api:5.1.0-SNAPSHOT' - } - - openApiGenerate { - mainClass = 'test.SampleApp' - systemProperties = [ - 'spring.main.banner-mode': 'off' - ] - } - """); + Files.writeString(testProjectDir.resolve("build.gradle"), + buildGradle("webmvc", """ + mainClass = 'test.SampleApp' + systemProperties = [ + 'spring.main.banner-mode': 'off' + ] + """)); BuildResult result = GradleRunner.create() .withProjectDir(testProjectDir.toFile()) @@ -114,30 +79,15 @@ void generatesOpenApiSpecFromServletApp() throws IOException { @Test void skipFlagProducesNoSpec() throws IOException { + Path sampleApp = Paths.get("src/test/resources/sample-app-webflux"); copyRecursively(sampleApp, testProjectDir); Files.writeString(testProjectDir.resolve("settings.gradle"), "rootProject.name = 'sample-app-skip'\n"); - Files.writeString(testProjectDir.resolve("build.gradle"), """ - plugins { - id 'java' - id 'io.github.vpelikh.springdoc-openapi-gradle-plugin' - } - - repositories { - mavenLocal() - mavenCentral() - } - - dependencies { - implementation 'org.springframework.boot:spring-boot-starter-webflux:4.1.1' - implementation 'io.github.vpelikh:springdoc-openapi-starter-webflux-api:5.1.0-SNAPSHOT' - } - - openApiGenerate { - mainClass = 'test.SampleApp' - skip = true - } - """); + Files.writeString(testProjectDir.resolve("build.gradle"), + buildGradle("webflux", """ + mainClass = 'test.SampleApp' + skip = true + """)); BuildResult result = GradleRunner.create() .withProjectDir(testProjectDir.toFile()) @@ -154,30 +104,15 @@ void skipFlagProducesNoSpec() throws IOException { @Test void generatesOpenApiYamlFormat() throws IOException { + Path sampleApp = Paths.get("src/test/resources/sample-app-webflux"); copyRecursively(sampleApp, testProjectDir); Files.writeString(testProjectDir.resolve("settings.gradle"), "rootProject.name = 'sample-app-yaml'\n"); - Files.writeString(testProjectDir.resolve("build.gradle"), """ - plugins { - id 'java' - id 'io.github.vpelikh.springdoc-openapi-gradle-plugin' - } - - repositories { - mavenLocal() - mavenCentral() - } - - dependencies { - implementation 'org.springframework.boot:spring-boot-starter-webflux:4.1.1' - implementation 'io.github.vpelikh:springdoc-openapi-starter-webflux-api:5.1.0-SNAPSHOT' - } - - openApiGenerate { - mainClass = 'test.SampleApp' - format = 'yaml' - } - """); + Files.writeString(testProjectDir.resolve("build.gradle"), + buildGradle("webflux", """ + mainClass = 'test.SampleApp' + format = 'yaml' + """)); BuildResult result = GradleRunner.create() .withProjectDir(testProjectDir.toFile()) @@ -197,6 +132,36 @@ void generatesOpenApiYamlFormat() throws IOException { "expected YAML output but got JSON: " + content); } + /** + * Builds the sample app build.gradle for the functional tests. + * @param starterModule springdoc starter module suffix, e.g. "webflux" or "webmvc". + * @param openApiExtension the extra {@code openApiGenerate { ... }} block body. + */ + private String buildGradle(String starterModule, String openApiExtension) { + String bootDependency = "implementation 'org.springframework.boot:spring-boot-starter-" + starterModule + ":4.1.1'\n"; + String springdocDependency = + "implementation 'io.github.vpelikh:springdoc-openapi-starter-" + starterModule + "-api:" + SPRINGDOC_VERSION + "'\n"; + return """ + plugins { + id 'java' + id 'io.github.vpelikh.springdoc-openapi-gradle-plugin' + } + + repositories { + mavenLocal() + mavenCentral() + } + + dependencies { + """ + bootDependency + springdocDependency + """ + } + + openApiGenerate { + """ + openApiExtension + """ + } + """; + } + private void copyRecursively(Path source, Path target) throws IOException { try (var stream = Files.walk(source)) { for (Path src : (Iterable) stream::iterator) { @@ -211,4 +176,4 @@ private void copyRecursively(Path source, Path target) throws IOException { } } } -} \ No newline at end of file +}