Custom Test task not working on Gradle 9.2

I’ve just upgraded to Gradle 9.2, and now a custom Test task that I have is not working. Previously I was using Gradle 8.14.3.

The custom Test task is defined as follows:

tasks {
    ...
    register<Test>("integrationTest") {
        group = "verification"

        useJUnitPlatform()

        shouldRunAfter(test)

        filter {
            excludeTestsMatching("*Test")
            includeTestsMatching("*ITCase")
        }
     }
    ...
}

On Gradle 8.14.3, this task works perfectly. It compiles the code and runs all the integration tests, based on the test’s name. In Gradle 9.2, it doesn’t work at all. The task appears to have no dependencies, and when it runs, it just says “No Source”.

Example of running it through IntelliJ:

Task :integrationTest NO-SOURCE
BUILD SUCCESSFUL in 114ms
Consider enabling configuration cache to speed up this build:  https://docs.gradle.org/9.2.0/userguide/configuration_cache_enabling.html
2:18:45 pm: Execution finished ‘integrationTest’.

I have no idea what’s changed between 8.14.3 and 9.2 that’s causing this, and I’m hoping some people more familiar with Gradle than me can tell me what’s changed and what I need to do to fix this. :slight_smile: I’m guessing there’s a different way of registering custom tasks, or something.

I’ve figured it out; it’s because of this change in Gradle 9: Upgrading to Gradle 9.0.0

Following the listed fix of adding the sources from the test task to my custom Test task fixes the problem.

1 Like

Before upgrading a major version, you should always solve all deprecation warnings by Gradle, as breaking changes are (short of unintentional ones) always done only in a major version and after a deprecation cycle.

So for a smooth upgrade experience:

  • update to the latest patch version within the same major version
  • update all plugins as far as possible
  • fix all deprecation warnings
  • update to the latest patch version in the directly following major version, considering the upgrade notes and release notes
  • repeat from second step on above until reaching the target version

This usually ensures a pretty smooth upgrade experience.

1 Like