'Gradle multi-project only executes tests for one project

I have a multi-project gradle build with four Kotlin Multiplatform modules, two of which have tests. When I run gradle check, if any of the tests from one of the modules fails, the tests for the other module do not get executed.

I'm using Gradle 7.3, Java 17 and kotlin.test. Tests for both projects are located in the commonTest source set. Also tried Gradle 7.1 and Java 11 with the same behavior.

Excerpt from settings.gradle.kts:

include(":ProjectA")
include(":ProjectB") // B has tests and depends on D, its tests are run
include(":ProjectC")
include(":ProjectD") // D has tests but are not run

Excerpt from ProjectB build.gradle.kts:

 sourceSets {
        val commonMain by getting {
            dependencies {
                api(compose.runtime)
                api(compose.foundation)
                api(compose.material)
                implementation(project(":ProjectD"))
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }

From the output of gradle check I can see that :ProjectB:allTests gets executed and fails but :ProjectB:allTests never gets executed. This is an excerpt from the gradle output:

> Task :ProjectB:desktopTest

com.mylibrary.AppTest[desktop] > helloTestNg[desktop] FAILED
    java.lang.AssertionError at AppTest.kt:8

2 tests completed, 1 failed
There were failing tests

> Task :ProjectB:allTests FAILED

FAILURE: Build failed with an exception.

If I do gradle -p ProjectD check tests for ProjectD are executed correctly.



Solution 1:[1]

Default Gradle behavior is to stop if any task fails, and Gradle considers a failing test as failing the check task. As a consequence, if any test fails in a certain project, the tests for the projects that have not yet been executed will not get executed.

The --continue can be useful in this case, it changes the default behavior and forces Gradle to continue executing all tasks even if some of them failed.

In this issue it is very well explained https://youtrack.jetbrains.com/issue/KT-49858p

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jordi