skylot / jadx

Dex to Java decompiler
Apache License 2.0
41.68k stars 4.88k forks source link

[build] `gradlew clean build dist` not rerunning tests #2283

Closed skylot closed 1 month ago

skylot commented 1 month ago

Issue details

clean task suppose to clean everything including tests cache, but sometimes tests still not running again. --rerun-tasks should help, but it fails spotless task in eclipse formatter with ClassNotFoundException

Discussion started in https://github.com/skylot/jadx/pull/2280#issuecomment-2360534536

Jadx version

dev

Java version

17 and 21

OS

skylot commented 1 month ago

@jpstotz I can confirm gradlew clean build dist not rerunning test for me on Windows, but works fine on Linux.

I will try to investigate this and try suggestions from https://stackoverflow.com/questions/29427020/how-to-run-gradle-test-when-all-tests-are-up-to-date

skylot commented 1 month ago

According to https://github.com/gradle/gradle/issues/9153 clean task just delete tests output, but not delete cache and this is expected behavior. It makes sense because if code not changed there is no point in running tests again. But most tests in core are integration tests, they depend on other modules like input plugins. To force rerun, we can use this:

tasks.test {
    outputs.upToDateWhen { false }
}

Although, here is an article why this is a bad approach :rofl:

Another approach is using --no-build-cache to disable build cache, and with clean task it is works fine for me. Or disable cache only for integration tests like this:

tasks.test {
    outputs.cacheIf  { false }
}

Another option is to rerun only tests:

.\gradlew test --rerun-tasks

I think this is the best approach for now.

About spotless rerun issues, turns out it is some kind of threading issue, because error always different, and it solved by disabling parallel task execution. Anyway it looks like spotless issue :cry:

skylot commented 1 month ago

As a result, I decided to disable cache for jadx-core tests. Most of them are integration tests and depends on plugins from other modules and also on environment (JDK version/provider and env variables), so it is fine to rerun these.

@jpstotz can you check if these changes works for your use cases? :slightly_smiling_face:

jpstotz commented 1 month ago

@skylot Thanks for fixing that. I just verified it in my home environment (Win 11, Adoptium JDK 17).

I had checked out master branch from September 12th and even after resetting the repo via git reset --hard and git clean -fdx between two runs of gradlew clean build dist the tests were omitted on the second gradle run.

Then the same test after updating to the lates master branch version. This time on second gradle run I was able to observe that all 804 tests from :jadx-core:test were executed again.