"Class path has changed" after adding "--scan"

When I add “–scan”, all tasks are executed because of “Class path of task ‘taskName’ has changed from XYZ to ZYX.” As result, all task are not up-to-date and executed again. Same with build cache.

Why it’s important for me:
I want to understand why remote cache is not used on my machine and why. But I cannot use --scan for that, because it makes cache invalid by itself.

I’ve created a new project in Android Studio without any changes.

Execute ./gradlew assembleDebug --build-cache
Result: 27 actionable tasks: 27 executed

Execute again ./gradlew assembleDebug --build-cache
Result: 27 actionable tasks: 27 up-to-date

Execute ./gradlew assembleDebug --build-cache --scan
Result: 27 actionable tasks: 27 executed
Build scan: https://scans.gradle.com/s/5lrsgbkrp6kze/performance/execution

Thanks for your help!

Sorry, for dumb question. Of course, it changes class path because it adds additional plugin into class path.

I solved my issue by applying build-scan plugin to my project. Like that plugin is always present, but it publishes build scan only when I add --scan command.

Its definitely not a dumb question. I can not reproduce this problem as applying --scan or not doesn’t change the output of the task (up-to-date, cached)? can you create a small reproducable example?

Simple project to reproduce my steps: https://github.com/MyDogTom/build-scan-classpath

In branch “apply-plugin” (https://github.com/MyDogTom/build-scan-classpath/tree/apply-plugin) I solved issue by applying “build-scan” plugin (see this commit: https://github.com/MyDogTom/build-scan-classpath/commit/db2eab61c86cd9735f703216731e364d07bde1aa )

Hey Svyatoslav,

thank you very much for the example project. It seems something in the org.jetbrains.kotlin.jvm plugin introduces this unexpected behaviour. I also see that potential tasks of type JavaCompile also rerun but caused by One or more additional actions for task ':compileJava' have changed.. The reason for that is that the classpath of the doLast provided by the kotlin.jvm plugin has also changed by applying the build scan plugin. I’ve raised https://github.com/gradle/gradle/issues/8161 in the gradle issue tracker for that problem.
Your fix by applying the plugin firsthand in the build script is the best fix for now I think.