From d1dd29c0b0183aa221cdfc13532ec0f1b6a018d7 Mon Sep 17 00:00:00 2001 From: Inf1mum Date: Sun, 15 Nov 2026 15:24:42 +0300 Subject: [PATCH 1/2] fix: make the build compatible with the Gradle version of consumer builds What: - Configure the jacoco test report with the required property instead of the removed enabled method-call syntax - Move the shadow plugin to the plugins DSL of the cli module and bump it to 7.1.2, the last version that works on both Gradle 7.6.x and 8.x - Replace the end-of-life jcenter() with mavenCentral() in the buildscript repositories Why: When a consumer build resolves the gradle plugin from this repository as a source control dependency (issue #735), Gradle evaluates the build files of this repository with the Gradle version of the consumer. With modern consumer builds such as the Gradle 8.6 of the issue report this fails with 'Could not find method enabled() for arguments [true] on Report xml' and shadow 6.1.0 references org.gradle.api.plugins.MavenPlugin which was removed in Gradle 8. How: xml.required works since Gradle 7.1 and shadow 7.1.2 applied through the plugins DSL resolves from the plugin portal on both Gradle 7.6.2 (the wrapper of this repository) and Gradle 8.x, so the source build evaluates and the plugin resolves in consumer builds. Signed-off-by: Inf1mum --- build.gradle | 7 +++---- cli/build.gradle | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index f4d8e58a..63929749 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,11 @@ buildscript { repositories { - jcenter() + mavenCentral() maven { url "https://plugins.gradle.org/m2/" } } dependencies { - classpath 'com.github.jengelman.gradle.plugins:shadow:6.1.0' classpath "de.marcphilipp.gradle:nexus-publish-plugin:0.4.0" } } @@ -83,8 +82,8 @@ subprojects { jacocoTestReport { reports { - xml.enabled true - html.enabled false + xml.required = true + html.required = false } } diff --git a/cli/build.gradle b/cli/build.gradle index a6346b09..123d72ed 100644 --- a/cli/build.gradle +++ b/cli/build.gradle @@ -1,5 +1,6 @@ plugins { id "com.diffplug.spotless" version "6.25.0" + id 'com.github.johnrengelman.shadow' version '7.1.2' } apply plugin: 'application' @@ -20,8 +21,6 @@ dependencies { mainClassName = 'org.openapitools.openapistylevalidator.cli.Main' -apply plugin: 'com.github.johnrengelman.shadow' - def generatedVersionDir = "${buildDir}/generated-version" sourceSets { From 1853ed0a70d7517e0fceb1deeae556fc3d8594ce Mon Sep 17 00:00:00 2001 From: Inf1mum Date: Sun, 15 Nov 2026 16:18:52 +0300 Subject: [PATCH 2/2] test: cover the consumer source-build scenario of #735 What: - Add a functional test that applies the plugin from this repository's build logic with a modern consumer build (the Gradle 8.6 of the issue report) through an included build and asserts the validation task succeeds Why: Issue #735 reports that resolving the gradle plugin as a source control dependency fails on modern consumer builds, because Gradle evaluates this repository's build files with the Gradle version of the consumer. The preceding fix commit shipped without a test that exercises this scenario, so nothing would catch a regression when the build files move again. How: The test copies this repository without .git and build outputs into the functional test workspace, wires the copy as an included build in the pluginManagement block of a small consumer project, and runs the consumer build through TestKit with withGradleVersion("8.6"). Without the build file fixes this fails with 'Could not find method enabled() for arguments [true] on Report xml', the error behind the ResolveException of the issue report. Signed-off-by: Inf1mum --- ...leValidatorGradlePluginFunctionalTest.java | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/gradle-plugin/src/functionalTest/java/org/openapitools/openapistylevalidator/gradle/OpenAPIStyleValidatorGradlePluginFunctionalTest.java b/gradle-plugin/src/functionalTest/java/org/openapitools/openapistylevalidator/gradle/OpenAPIStyleValidatorGradlePluginFunctionalTest.java index 362c6b3f..e4bff96d 100644 --- a/gradle-plugin/src/functionalTest/java/org/openapitools/openapistylevalidator/gradle/OpenAPIStyleValidatorGradlePluginFunctionalTest.java +++ b/gradle-plugin/src/functionalTest/java/org/openapitools/openapistylevalidator/gradle/OpenAPIStyleValidatorGradlePluginFunctionalTest.java @@ -10,6 +10,14 @@ import java.io.IOException; import java.io.Writer; import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.StandardCopyOption; +import java.nio.file.FileVisitResult; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -68,6 +76,119 @@ public void validateWithOptionsMustBeASuccess() throws IOException { assertEquals(TaskOutcome.SUCCESS, result.task(":openAPIStyleValidator").getOutcome()); } + @Test + public void consumerSourceBuildMustWorkWithModernGradle() throws IOException { + // Reproduces the report of issue #735: the plugin applied straight from this + // repository's build logic, like a consumer build does with a source control + // dependency. Gradle evaluates the build files of the source build with the + // Gradle version of the consumer, so they must be compatible with the modern + // Gradle versions of consumer builds. + File workingDirectory = new File("build/functionalTest735"); + deleteRecursively(new File(workingDirectory, "source-build")); + deleteRecursively(new File(workingDirectory, "consumer")); + + File sourceBuild = new File(workingDirectory, "source-build"); + copyDirectory(new File("..").getCanonicalFile(), sourceBuild); + + File projectDir = new File(workingDirectory, "consumer"); + Files.createDirectories(projectDir.toPath()); + writeString(new File(projectDir, "openapi.yaml"), + "openapi: 3.0.1\n" + + "info:\n" + + " title: ping test\n" + + " version: '1.0'\n" + + "servers:\n" + + " - url: 'http://localhost:9999/'\n" + + "paths:\n" + + " /ping:\n" + + " post:\n" + + " operationId: pingGet\n" + + " responses:\n" + + " '201':\n" + + " description: OK"); + writeString(new File(projectDir, "settings.gradle"), + "pluginManagement {\n" + + " includeBuild('../source-build')\n" + + "}\n" + + "\n" + + "rootProject.name = 'issue-735-consumer'"); + writeString(new File(projectDir, "build.gradle"), + "plugins {\n" + + " id 'org.openapitools.openapistylevalidator'\n" + + "}\n" + + "\n" + + "openAPIStyleValidator {\n" + + " // set the input file option:\n" + + " inputFile = file('openapi.yaml')\n" + + "\n" + + " // customize the validation options:\n" + + " validateInfoLicense = false\n" + + " validateInfoDescription = false\n" + + " validateInfoContact = false\n" + + " validateOperationDescription = false\n" + + " validateOperationTag = false\n" + + " validateOperationSummary = false\n" + + "}"); + + // Run the build of the consumer with a modern Gradle version, + // like the Gradle 8.6 of the issue report + GradleRunner runner = GradleRunner.create(); + runner.forwardOutput(); + runner.withGradleVersion("8.6"); + runner.withTestKitDir(new File(workingDirectory, "testkit").getCanonicalFile()); + runner.withArguments("openAPIStyleValidator"); + runner.withProjectDir(projectDir); + BuildResult result = runner.build(); + + // Verify the result + assertEquals(TaskOutcome.SUCCESS, result.task(":openAPIStyleValidator").getOutcome()); + } + + private void deleteRecursively(File root) throws IOException { + if (!root.exists()) { + return; + } + Files.walkFileTree(root.toPath(), new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException { + Files.delete(file); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path directory, IOException exception) throws IOException { + Files.delete(directory); + return FileVisitResult.CONTINUE; + } + }); + } + + private void copyDirectory(File source, File target) throws IOException { + // Skip what the Gradle build does not need and what is too big to copy, + // most notably the build outputs that would conflict with the ones of the + // copied source build + Set excludedDirectories = new HashSet<>(Arrays.asList( + ".git", ".github", ".gradle", ".idea", "build", "docs", "node_modules", "website")); + Files.walkFileTree(source.toPath(), new SimpleFileVisitor() { + @Override + public FileVisitResult preVisitDirectory(Path directory, BasicFileAttributes attributes) { + if (!source.toPath().equals(directory) + && excludedDirectories.contains(directory.getFileName().toString())) { + return FileVisitResult.SKIP_SUBTREE; + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException { + Path targetPath = target.toPath().resolve(source.toPath().relativize(file)); + Files.createDirectories(targetPath.getParent()); + Files.copy(file, targetPath, StandardCopyOption.REPLACE_EXISTING); + return FileVisitResult.CONTINUE; + } + }); + } + private void writeString(File file, String string) throws IOException { try (Writer writer = new FileWriter(file)) { writer.write(string);