Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
}
Expand Down Expand Up @@ -83,8 +82,8 @@ subprojects {

jacocoTestReport {
reports {
xml.enabled true
html.enabled false
xml.required = true
html.required = false
}
}

Expand Down
3 changes: 1 addition & 2 deletions cli/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id "com.diffplug.spotless" version "6.25.0"
id 'com.github.johnrengelman.shadow' version '7.1.2'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Shadow 7.1.2 fails when applied with Gradle 8.x because it maps the removed Jar.classifier property. A Gradle 8.6 build that configures :cli fails during configuration; upgrade to a Gradle-8-compatible Shadow release such as 8.1.1.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At cli/build.gradle, line 3:

<comment>Shadow 7.1.2 fails when applied with Gradle 8.x because it maps the removed `Jar.classifier` property. A Gradle 8.6 build that configures `:cli` fails during configuration; upgrade to a Gradle-8-compatible Shadow release such as 8.1.1.</comment>

<file context>
@@ -1,5 +1,6 @@
 plugins {
     id "com.diffplug.spotless" version "6.25.0"
+    id 'com.github.johnrengelman.shadow' version '7.1.2'
 }
 
</file context>
Suggested change
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.github.johnrengelman.shadow' version '8.1.1'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not reproduced on 1853ed0. With Gradle 8.6, :openapi-style-validator-cli configures and shadowJar, shadowDistZip and shadowDistTar all succeed with Shadow 7.1.2 (BUILD SUCCESSFUL, 9 tasks executed). Same on 8.14.8. 8.1.1 would break this repo's own build: on the 7.6.2 wrapper it fails with This version of Shadow supports Gradle 8.0+ only. Please upgrade. 7.1.2 is the newest release that works on both, so I keep it.

}

apply plugin: 'application'
Expand All @@ -20,8 +21,6 @@ dependencies {

mainClassName = 'org.openapitools.openapistylevalidator.cli.Main'

apply plugin: 'com.github.johnrengelman.shadow'

def generatedVersionDir = "${buildDir}/generated-version"

sourceSets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Path>() {
@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<String> excludedDirectories = new HashSet<>(Arrays.asList(
".git", ".github", ".gradle", ".idea", "build", "docs", "node_modules", "website"));
Files.walkFileTree(source.toPath(), new SimpleFileVisitor<Path>() {
@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);
Expand Down