"NO-SOURCE" for "test" task, deleted build/ directory, only with build cache

I’m trying to debug some behaviour that I can’t quite understand, using Gradle 8.4 and Java 17.

My project contains several subprojects with associated “test” tasks. They execute as expected, Java sources are compiled, tests are run, coverage is computed, etc.

If I delete the subproject/build/ directory, things start to get strange.

With build cache disabled:

  1. rm subproject/build -r
  2. ./gradlew subproject:test results in test execution, as expected
  3. ./gradlew subproject:test results in “UP-TO-DATE”, as expected

With build cache enabled:

  1. rm subproject/build -r
  2. ./gradlew subproject:test results in “NO-SOURCE”

If I now delete ~/.gradle/caches/, I get this (with build cache enabled):

  1. rm ~/.gradle/caches -r followed by ./gradlew --stop
  2. rm subproject/build -r
  3. ./gradlew subproject:test results in test execution, as expected
  4. ./gradlew subproject:test results in “UP-TO-DATE”, as expected

I first noticed this strange behaviour after I aborted builds (CTRL+C). Subsequent builds failed for unknown reasons, which I believe are related to the “reproducer” described above.

Why does this “NO-SOURCE” appear? What can I do to further (help) debug this?

The more I experiment, the stranger it gets. I now also get compilation issues (“package does not exist”), even though the source code is fine and compiles without any issues.

Sounds to me like a corrupt build cache entry.
Especially as you mentioned aborted builds, I mean to remember there was an issue about invalid build cache entries being written when aborting in unlucky moments, but I cannot find it right now.

Yeah that might be it. I’ll clean all build caches and hope for the best.

1 Like