From 9e6709eda0c0d11fa8ca140b52cc602cf45af939 Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Wed, 15 Dec 2021 14:04:17 -0600 Subject: [PATCH] Enable caching for system tests in CI Setting the `systemTest` Gradle task output as never up-to-date ensures that all system tests are executed each time they are run in CI. The `--rerun-tasks` Gradle option that was used previously had the same effect but also disabled build caching. Closes gh-29029 --- .../boot/build/test/SystemTestPlugin.java | 11 +++++++++++ ci/scripts/run-system-tests.sh | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/test/SystemTestPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/test/SystemTestPlugin.java index e0352bbf02..634e110a69 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/test/SystemTestPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/test/SystemTestPlugin.java @@ -18,8 +18,10 @@ package org.springframework.boot.build.test; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.Task; import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.specs.Spec; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSetContainer; import org.gradle.api.tasks.testing.Test; @@ -35,6 +37,8 @@ import org.gradle.plugins.ide.eclipse.model.EclipseModel; */ public class SystemTestPlugin implements Plugin { + private static final Spec NEVER = (task) -> false; + /** * Name of the {@code systemTest} task. */ @@ -78,6 +82,13 @@ public class SystemTestPlugin implements Plugin { systemTest.setTestClassesDirs(systemTestSourceSet.getOutput().getClassesDirs()); systemTest.setClasspath(systemTestSourceSet.getRuntimeClasspath()); systemTest.shouldRunAfter(JavaPlugin.TEST_TASK_NAME); + if (isCi()) { + systemTest.getOutputs().upToDateWhen(NEVER); + } + } + + private boolean isCi() { + return Boolean.parseBoolean(System.getenv("CI")); } } diff --git a/ci/scripts/run-system-tests.sh b/ci/scripts/run-system-tests.sh index 4cb3025da6..c03ce1e823 100755 --- a/ci/scripts/run-system-tests.sh +++ b/ci/scripts/run-system-tests.sh @@ -5,8 +5,8 @@ source $(dirname $0)/common.sh pushd git-repo > /dev/null if [[ -d /opt/openjdk-toolchain ]]; then - ./gradlew -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false --no-daemon --max-workers=4 --rerun-tasks systemTest -PtoolchainVersion=${TOOLCHAIN_JAVA_VERSION} -Porg.gradle.java.installations.auto-detect=false -Porg.gradle.java.installations.auto-download=false -Porg.gradle.java.installations.paths=/opt/openjdk-toolchain/ + ./gradlew -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false --no-daemon --max-workers=4 systemTest -PtoolchainVersion=${TOOLCHAIN_JAVA_VERSION} -Porg.gradle.java.installations.auto-detect=false -Porg.gradle.java.installations.auto-download=false -Porg.gradle.java.installations.paths=/opt/openjdk-toolchain/ else - ./gradlew -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false --no-daemon --max-workers=4 --rerun-tasks systemTest + ./gradlew -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false --no-daemon --max-workers=4 systemTest fi popd > /dev/null