CC takes task options into account when computing the cache key, so changing the command line will cause the miss. However, latest IDEA can trigger test runs with the tooling API, and enjoy cache hits. We plan to address the command-line use case too:
https://github.com/gradle/gradle/issues/24550