Skip to content

Commit 04c8016

Browse files
committed
Fix testClassDirs deprecation warning with Gradle 8.1+
Closes gh-23
1 parent 7d271ab commit 04c8016

File tree

4 files changed

+80
-9
lines changed

4 files changed

+80
-9
lines changed

src/main/java/io/spring/gradle/compatibilitytest/CompatibilityTestPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2024 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -112,6 +112,7 @@ private void configureMatrixTestTask(Project project, Test compatibilityTest, Ja
112112
.eachDependency((details) -> dependencyVersions.stream()
113113
.filter((dependencyVersion) -> matches(dependencyVersion, details))
114114
.forEach((dependencyVersion) -> details.useVersion(dependencyVersion.getVersion())));
115+
compatibilityTest.setTestClassesDirs(testSourceSet.getOutput().getClassesDirs());
115116
compatibilityTest.setClasspath(
116117
project.files(javaCompile.getDestinationDirectory(), testSourceSet.getOutput().getResourcesDir(),
117118
sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput(), configuration));

src/test/java/io/spring/gradle/compatibilitytest/CompatibilityTestPluginIntegrationTests.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2024 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,12 +16,17 @@
1616

1717
package io.spring.gradle.compatibilitytest;
1818

19-
import org.gradle.testkit.runner.BuildResult;
20-
import org.junit.jupiter.api.Test;
21-
import org.junit.jupiter.api.extension.ExtendWith;
19+
import java.io.File;
20+
import java.io.FileWriter;
21+
import java.io.IOException;
22+
import java.io.PrintWriter;
2223

2324
import io.spring.gradle.compatibilitytest.testkit.GradleBuild;
2425
import io.spring.gradle.compatibilitytest.testkit.GradleBuildExtension;
26+
import org.gradle.testkit.runner.BuildResult;
27+
import org.gradle.testkit.runner.TaskOutcome;
28+
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.extension.ExtendWith;
2530

2631
import static org.assertj.core.api.Assertions.assertThat;
2732

@@ -117,4 +122,30 @@ void javaCompileTaskIsCreatedForEachPermutation() {
117122
"compileCompatibilityTestJava_spring_framework_5.3.1");
118123
}
119124

125+
@Test
126+
void testsAreExecutedWithoutDeprecationWarnings() throws IOException {
127+
File projectDir = this.gradleBuild.getProjectDir();
128+
File exampleTests = new File(projectDir, "src/test/java/example/ExampleTests.java");
129+
exampleTests.getParentFile().mkdirs();
130+
try (PrintWriter writer = new PrintWriter(new FileWriter(exampleTests))) {
131+
writer.println("package example;");
132+
writer.println("");
133+
writer.println("import org.junit.jupiter.api.Test;");
134+
writer.println("");
135+
writer.println("class ExampleTests {");
136+
writer.println("");
137+
writer.println(" @Test");
138+
writer.println(" void test() {");
139+
writer.println(" }");
140+
writer.println("");
141+
writer.println("}");
142+
}
143+
BuildResult result = this.gradleBuild.gradleVersion("8.1").build("build");
144+
assertThat(result.task(":compatibilityTest_spring_framework_5.3.0").getOutcome())
145+
.isEqualTo(TaskOutcome.SUCCESS);
146+
assertThat(result.task(":compatibilityTest_spring_framework_5.3.1").getOutcome())
147+
.isEqualTo(TaskOutcome.SUCCESS);
148+
assertThat(result.getOutput()).doesNotContain("deprecated");
149+
}
150+
120151
}

src/test/java/io/spring/gradle/compatibilitytest/testkit/GradleBuild.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,6 +40,8 @@ public class GradleBuild {
4040

4141
private String script;
4242

43+
private String gradleVersion;
44+
4345
void before() throws IOException {
4446
this.projectDir = Files.createTempDirectory("gradle-").toFile();
4547
}
@@ -67,6 +69,11 @@ public GradleBuild script(String script) {
6769
return this;
6870
}
6971

72+
public GradleBuild gradleVersion(String gradleVersion) {
73+
this.gradleVersion = gradleVersion;
74+
return this;
75+
}
76+
7077
public BuildResult build(String... arguments) {
7178
try {
7279
return prepareRunner(arguments).build();
@@ -81,10 +88,12 @@ public GradleRunner prepareRunner(String... arguments) throws IOException {
8188
StandardCopyOption.REPLACE_EXISTING);
8289
GradleRunner gradleRunner = GradleRunner.create()
8390
.withProjectDir(this.projectDir)
84-
.withPluginClasspath(pluginClasspath());
85-
gradleRunner.withDebug(true);
91+
.withPluginClasspath(pluginClasspath())
92+
.withDebug(true);
93+
if (this.gradleVersion != null) {
94+
gradleRunner = gradleRunner.withGradleVersion(this.gradleVersion);
95+
}
8696
List<String> allArguments = new ArrayList<>();
87-
allArguments.add("--stacktrace");
8897
allArguments.addAll(Arrays.asList(arguments));
8998
allArguments.add("--warning-mode");
9099
allArguments.add("all");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
plugins {
2+
id 'io.spring.compatibility-test'
3+
id 'java'
4+
}
5+
6+
repositories {
7+
mavenCentral()
8+
}
9+
10+
compatibilityTest {
11+
dependency('Spring Framework') { springFramework ->
12+
springFramework.groupId = 'org.springframework'
13+
springFramework.versions = [
14+
'5.3.0',
15+
'5.3.1'
16+
]
17+
}
18+
}
19+
20+
dependencies {
21+
implementation 'org.springframework:spring-core:5.2.10.RELEASE'
22+
23+
testImplementation 'org.junit.jupiter:junit-jupiter:5.13.0'
24+
25+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.13.0'
26+
}
27+
28+
tasks.withType(Test).configureEach {
29+
useJUnitPlatform();
30+
}

0 commit comments

Comments
 (0)