Tom Yuval
08/22/2022, 2:04 PM./gradlew allTests
or ./gradlew check
), this doesn’t work when I’ve already run the tests before. What happens is that the first time I run gradlew
it indeed fails because of the failing tests, but then if I run it a second time it doesn’t run the tests again as the tasks are already “up-to-date” – but it also doesn’t fail (as if the tasks being up-to-date is a good enough reason to pass, even though the tasks’ up-to-date state is that they’re failing).
Is there some way to tell Gradle to fail when the “up-to-date” tasks it doesn’t want to run again failed the last time?
Clarification: I’m not asking how to make Gradle rerun the tests – if nothing’s changed since the last run then I’m happy with Gradle considering everything up-to-date and not wasting time re-executing tasks. I just want it to fail (= return with a non-zero exit code) in that state, like it did upon the first run of the failing tests, and not “pretend” that everything’s OK.Sam
08/22/2022, 2:07 PMignoreFailure = true
?Vampire
08/22/2022, 2:23 PMTom Yuval
08/22/2022, 2:26 PMfail
, and that’s it. Running ./gradlew check
fails because of the failing test, but rerunning it exits with no error.Vampire
08/22/2022, 2:26 PMTom Yuval
08/22/2022, 2:29 PMplugins {
kotlin("multiplatform") version "1.7.10"
}
group = "com.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
js(IR) {
browser {
commonWebpackConfig {
cssSupport.enabled = true
}
}
}
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting
val jvmTest by getting
val jsMain by getting
val jsTest by getting
val nativeMain by getting
val nativeTest by getting
}
}
`src/commonTest/kotlin/T.kt`:
import kotlin.test.Test
import kotlin.test.fail
class T {
@Test fun t() { fail("Supposed to fail") }
}
Tom Yuval
08/22/2022, 2:33 PM> ./gradlew check
> Configure project :
Kotlin Multiplatform Projects are an Alpha feature. See: <https://kotlinlang.org/docs/reference/evolution/components-stability.html>. To hide this message, add 'kotlin.mpp.stability.nowarn=true' to the Gradle properties.
The property 'kotlin.mpp.enableGranularSourceSetsMetadata=true' has no effect in this and future Kotlin versions, as Hierarchical Structures support is now enabled by default. It is safe to remove the property.
The property 'kotlin.native.enableDependencyPropagation=false' has no effect in this and future Kotlin versions, as Kotlin/Native dependency commonization is now enabled by default. It is safe to remove the property.
> Task :jvmTest
T[jvm] > t()[jvm] FAILED
org.opentest4j.AssertionFailedError at T.kt:8
1 test completed, 1 failed
There were failing tests
> Task :jsBrowserTest
T.t FAILED
AssertionError at /var/folders/5r/jzhxz6rd7fz236lzbs9sm7m00000gn/T/_karma_webpack_670497/commons.js:17012
1 test completed, 1 failed
There were failing tests
> Task :nativeTest
T.t FAILED
kotlin.AssertionError at /opt/buildAgent/work/67fbc2b507315583/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Throwable.kt:24
1 test completed, 1 failed
There were failing tests
> Task :allTests FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':allTests'.
> There were failing tests. See the report at: file:///path/to/project/build/reports/tests/allTests/index.html
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at <https://help.gradle.org>
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See <https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings>
BUILD FAILED in 10s
22 actionable tasks: 12 executed, 10 up-to-date
Tom Yuval
08/22/2022, 2:34 PM./gradlew check
(with nothing else done in between):
> ./gradlew check
> Configure project :
Kotlin Multiplatform Projects are an Alpha feature. See: <https://kotlinlang.org/docs/reference/evolution/components-stability.html>. To hide this message, add 'kotlin.mpp.stability.nowarn=true' to the Gradle properties.
The property 'kotlin.mpp.enableGranularSourceSetsMetadata=true' has no effect in this and future Kotlin versions, as Hierarchical Structures support is now enabled by default. It is safe to remove the property.
The property 'kotlin.native.enableDependencyPropagation=false' has no effect in this and future Kotlin versions, as Kotlin/Native dependency commonization is now enabled by default. It is safe to remove the property.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See <https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings>
BUILD SUCCESSFUL in 1s
22 actionable tasks: 2 executed, 20 up-to-date
Tom Yuval
08/22/2022, 2:37 PMkotlinlang
Slack and don’t know if there’s a better way to supply MCVEs.)Vampire
08/22/2022, 2:53 PMTom Yuval
08/22/2022, 4:04 PMVampire
08/22/2022, 11:12 PMcheck
three times and every time the tests were executed.Vampire
08/22/2022, 11:13 PM<GRADLE_USER_HOME>
and the .gradle
in your project and test again.Tom Yuval
08/23/2022, 11:38 AM.gradle
, as it is Git-ignored) and the same problem repeated.
Deleting <GRADLE_USER_HOME>
might help, but I’m not sure what that is – do you mean ~/.gradle
?Vampire
08/23/2022, 12:05 PMTom Yuval
08/23/2022, 1:33 PMVampire
08/23/2022, 1:34 PMTom Yuval
08/23/2022, 1:36 PMIf there is a problem, you probably have to bring this up with JetBrains and their Kotlin plugin.Would love to do that! Anyone from JetBrains and their Kotlin plugin around here?
Vampire
08/23/2022, 1:39 PMTom Yuval
08/23/2022, 1:43 PMTom Yuval
08/26/2022, 1:55 PMVampire
08/26/2022, 3:33 PMVampire
08/26/2022, 3:35 PMTom Yuval
08/26/2022, 3:55 PMVampire
08/26/2022, 3:55 PMallTests
task is rerun as it failed last time, but now does not fail as it obviously only fails if the individual test tasks had failures.Vampire
08/26/2022, 3:56 PMTom Yuval
08/26/2022, 4:01 PMVampire
08/26/2022, 4:03 PMTom Yuval
08/26/2022, 5:40 PM