Skip to content

Commit

Permalink
Resolve Gradle deprecation warnings in integration tests
Browse files Browse the repository at this point in the history
Moreover, tests will now fail when new deprecation warnings are emitted.
  • Loading branch information
marcphilipp committed Nov 20, 2024
1 parent d9f9122 commit 151cd36
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ repositories {

// grab jupiter version from system environment
val jupiterVersion = System.getenv("JUNIT_JUPITER_VERSION")
val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION")

dependencies {
testImplementation(kotlin("stdlib-jdk8"))
testImplementation("org.junit.jupiter:junit-jupiter:$jupiterVersion")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:$platformVersion")
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}

tasks.withType<KotlinCompile>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.java.installations.fromEnv=JDK8
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:$jupiterVersion") {
exclude(group = "org.junit.jupiter", module = "junit-jupiter-engine")
}
testRuntimeOnly("org.junit.platform:junit-platform-launcher:$platformVersion")}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}

tasks.test {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.java.installations.fromEnv=JDK8
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ plugins {

// grab jupiter version from system environment
val jupiterVersion: String = System.getenv("JUNIT_JUPITER_VERSION")
val vintageVersion: String = System.getenv("JUNIT_VINTAGE_VERSION")
val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION")

repositories {
Expand All @@ -17,11 +16,17 @@ dependencies {
testRuntimeOnly("org.junit.platform:junit-platform-reporting:$platformVersion")
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}

tasks.test {
useJUnitPlatform()

testLogging {
events("passed", "skipped", "failed")
events("passed", "skipped", "failed", "standardOut")
}

reports {
Expand All @@ -35,8 +40,4 @@ tasks.test {
"-Djunit.platform.reporting.output.dir=${outputDir.get().asFile.absolutePath}"
)
}

doFirst {
println("Using Java version: ${JavaVersion.current()}")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.java.installations.fromEnv=JDK8
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

class CalculatorTests {

@BeforeAll
static void printJavaVersion() {
System.out.println("Using Java version: " + System.getProperty("java.specification.version"));
}

@Test
@DisplayName("1 + 1 = 2")
void addsTwoNumbers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ dependencies {
testRuntimeOnly("org.junit.platform:junit-platform-reporting:$platformVersion")
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}

tasks.test {
useJUnitPlatform()

testLogging {
events("failed")
events("failed", "standardOut")
}

reports {
Expand All @@ -36,8 +42,4 @@ tasks.test {
"-Djunit.platform.reporting.output.dir=${outputDir.get().asFile.absolutePath}"
)
}

doFirst {
println("Using Java version: ${JavaVersion.current()}")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.java.installations.fromEnv=JDK8
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Arrays;
import java.util.stream.Stream;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DynamicNode;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor;
Expand All @@ -31,6 +32,11 @@

class ReflectionTestCase {

@BeforeAll
static void printJavaVersion() {
System.out.println("Using Java version: " + System.getProperty("java.specification.version"));
}

@TestFactory
Stream<DynamicNode> canReadParameters() {
return Stream.of(JupiterTestDescriptor.class, ClassBasedTestDescriptor.class, ClassTestDescriptor.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ dependencies {
exclude(group = "junit")
because("we want to override it to test against different versions")
}

val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:$platformVersion")
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}

tasks.test {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.java.installations.fromEnv=JDK8
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ void runsTestsInNativeImage() {
.setTool(new GradleWrapper(Paths.get(".."))) //
.setProject(Projects.GRAALVM_STARTER) //
.addArguments("-Dmaven.repo=" + MavenRepo.dir()) //
.addArguments("javaToolchains", "nativeTest", "--no-daemon", "--stacktrace", "--no-build-cache") //
.addArguments("javaToolchains", "nativeTest", "--no-daemon", "--stacktrace", "--no-build-cache",
"--warning-mode=fail") //
.setTimeout(Duration.ofMinutes(10)) //
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ void gradle_wrapper() {
.setTool(new GradleWrapper(Paths.get(".."))) //
.setProject(Projects.GRADLE_KOTLIN_EXTENSIONS) //
.addArguments("-Dmaven.repo=" + MavenRepo.dir()) //
.addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache") //
.addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache", "--warning-mode=fail") //
.setTimeout(TOOL_TIMEOUT) //
.setJavaHome(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) //
.putEnvironment("JDK8", Helper.getJavaHome("8").orElseThrow(TestAbortedException::new).toString()) //
.build() //
.run();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ private void test(Tool gradle) {
.setProject(Projects.GRADLE_MISSING_ENGINE) //
.setTool(gradle) //
.addArguments("-Dmaven.repo=" + MavenRepo.dir()) //
.addArguments("build", "--no-daemon", "--debug", "--stacktrace", "--no-build-cache") //
.setJavaHome(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) //
.addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache", "--warning-mode=fail") //
.putEnvironment("JDK8", Helper.getJavaHome("8").orElseThrow(TestAbortedException::new).toString()) //
.setTimeout(TOOL_TIMEOUT).build() //
.run();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ void gradle_wrapper() {
.setTool(new GradleWrapper(Paths.get(".."))) //
.setProject(Projects.GRADLE_STARTER) //
.addArguments("-Dmaven.repo=" + MavenRepo.dir()) //
.addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache") //
.addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache", "--warning-mode=fail") //
.setTimeout(TOOL_TIMEOUT) //
.setJavaHome(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) //
.putEnvironment("JDK8", Helper.getJavaHome("8").orElseThrow(TestAbortedException::new).toString()) //
.build();

var result = request.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ void gradle_wrapper() {
.setTool(new GradleWrapper(Paths.get(".."))) //
.setProject(Projects.REFLECTION_TESTS) //
.addArguments("-Dmaven.repo=" + MavenRepo.dir()) //
.addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache") //
.addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache", "--warning-mode=fail") //
.setTimeout(TOOL_TIMEOUT) //
.setJavaHome(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) //
.putEnvironment("JDK8", Helper.getJavaHome("8").orElseThrow(TestAbortedException::new).toString()) //
.build();

var result = request.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ void supportedVersions(String version) {
private Result run(String version) {
var result = Request.builder() //
.setTool(new GradleWrapper(Paths.get(".."))) //
.setJavaHome(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) //
.putEnvironment("JDK8", Helper.getJavaHome("8").orElseThrow(TestAbortedException::new).toString()) //
.setProject(Projects.VINTAGE) //
.setWorkspace("vintage-gradle-" + version) //
.addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache") //
.addArguments("build", "--no-daemon", "--stacktrace", "--no-build-cache", "--warning-mode=fail") //
.addArguments("-Dmaven.repo=" + MavenRepo.dir()) //
.addArguments("-Djunit4Version=" + version) //
.setTimeout(TOOL_TIMEOUT) //
Expand Down

0 comments on commit 151cd36

Please sign in to comment.