Test task failing after upgrading from 7.2 to 8.5

Hello,
I have a multi-project Java project which i have been building with Gradle 7.2 for 2 years now.
After i have upgraded Gradle from 7.2 to version 8.5 following the [official] page, my test task is failing

project
---subProjectA
   --build.gradle
---subProjectB
   --build.gradle
---subProjectC
   --build.gradle
build.gradle
settings.gradle
projects.gradle

This up here is a very high level representation of the project.
When i run the test task for a subproject i get:

./gradlew :subProjectA:test
> Task :subProjectA:test SKIPPED
Skipping task ':subProjectA:test' as task onlyIf 'Task is enabled' is false.

I dont understand why this has happened, i nowhere can see that i explicitly set that predicate to false: onlyIf 'Task is enabled'
I notice though that if in subProjectA > build.gradle I explicitly enable the test task:

test {
  enabled = true
}

that then the tests run fine.
but i have many subprojects and i dont want to override the test task and add that boolean flag in every subproject.
So first i wanted to know whether this si a default behavior added in Gradle 8.5 (but i fail to see it in release notes), and second, if i really do need to set the enabled=true flag, how can i set that for all subprojects?
I tried the following in the root’s build.gradle:

allprojects {
  test {
   enabled = true
  }
}

But it wont work…
I hope this is enough information to understand the problem
(Upgrading your build from Gradle 7.x to 8.0)

You deducted correctly that the error message means enabled is set to false.
But no, it wouldn’t make any sense if test tasks would be disabled by default.
Either somewhere your build scripts or some plugin you apply has to set enabled = false for this to happen.
If you don’t find where it is set to false, maybe run your build through the debugger with a breakpoint in org.gradle.api.internal.AbstractTask#setEnabled which should then hopefully reveal the culprit.

Regarding setting something on all projects, you should never use something like allprojects { ... }, subprojects { ... }, project("...") { ... }, or similar ways of doing cross-project configuration. Those immediately introduce project coupling which is discouraged bad practice, and also works against some more sophisticated Gradle features and optimizations. If you want to do something in multiple projects you should create a convention plugin with your conventions in buildSrc or an included build like gradle/build-logic, for example implemented as precompiled script plugin.

Thanks Vampire!
But is very puzzling why this happened, so basically this is the test task definition i had when i was still running on Gradle 7.2:

test {
    useJUnitPlatform()
    maxHeapSize = '2G'
    testLogging {
      events "passed", "skipped", "failed"
      showStandardStreams = true
      exceptionFormat = 'full'
    }

    reports {
      junitXml.enabled = true
      html.enabled = false
    }
  }

After upgrade i was getting a compilation error and i edited that block to the following:

  test {
    useJUnitPlatform()
    maxHeapSize = '2G'
    testLogging {
      events "passed", "skipped", "failed"
      showStandardStreams = true
      exceptionFormat = 'full'
    }

    reports {
      junitXml {
        enabled true
      }
      html {
        enabled false
      }
    }
  }

And then the problem started, if now i remove:

    reports {
      junitXml {
        enabled true
      }
      html {
        enabled false
      }
    }

It runs fine and the test executes!
But how come the html.enable = false, sets the test task to false??
Am confused

I have now set it like this, it seems to work fine:

  reports {
      junitXml {
        enabled
      }
      html {
        !enabled
      }
    }

Ah, now that you showed the relevant parts it is not at all puzzling.
You just showed where you disable the task.

Two general advices:

  1. Switch to Kotlin DSL, by now it is the default DSL, you immediately get type-safe build scripts, actually helpful error messages if you mess up the syntax, and an amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio. With that you probably would already have spotted the problem yourself already.

  2. Never jump over the last patch version within a major version when doing upgrades if you want to minimized hassle. If you would have updated to 7.6.3 first and solved all deprecation warnings you would not have had this problem, because you would have got a deprecation warning for html.enabled and juntiXml.enabled that tells you to use required instead. So for smooth udpate experience:

    • update to latest patch version within the current major version
    • fix all deprecation warnings
    • update to the latest patch version within the directly following major version
    • fix all deprecation warnings
    • rinse and repeat

    And actually you also linked to the right page already that also mentions the change, here with anchor the concrete section: Upgrading your build from Gradle 7.x to 8.0

1 Like