I'm wondering why running `./gradlew check` versu...
# gradle
j
I'm wondering why running
./gradlew check
versus running the
check
gradle task from intellij gradle plugin, is not providing the same results. When running from Intellij, it's using some annoying cache, which causes not to run all tests (even if running the
clean
task beforehand). Anyone know why or how I can force intellij to run all tests when running the
check
gradle task?
j
clean doesn’t mean running all again, if everything is saved in the build cache, it will be reused as inputs and outputs are not changing
v
If it is a multi-project build, a difference is, that running
check
from the tool window in IntelliJ is like running
./gradlew :check
so just running the task in the selected project, for example root project, while
./gradlew check
runs
check
in all projects of the build where it exists.
👍 2
j
That sounds like what's happening for me
I have a multi-project setup and would like to run all tests across all projects, and would like to stay away from the command line
the
:check
that is being run by Intellij, is running all tests (sometimes). Do you know how I could make sure that it will run all tests?
v
Why do you actually want to run all tests? If you say sometimes it runs all tests, it is not what I described. So if Gradle decides that the tests do not need to run because neither inputs nor outputs were touched, why would you want to run all tests anyway?
j
Good question 😛 I just don't feel comfortable always with the cache, so I want to see the green tests. Maybe I shall just trust gradle more
v
Oh, and I remembered wrongly or it changed. It seems you cannot run a task targetedly from just a specific project currently, but I more consider that a bug.
Maybe I shall just trust gradle more
Probably. 😄 You could use "Run anything" (Ctrl+Ctrl) And then type in "gradle test --rerun" or "gradle check --rerun-tasks"
❤️ 3
j
I can see all the projects in the gradle tool window, but instead of opening the tasks within a specific project I just go directly into
Tasks > verification > check
a
Are your tests deterministic, or do they use random data? If they're random, you can add a seed to the test task https://blog.gradle.org/stop-rerunning-tests I certainly found Gradle skipping tests a bit freaky at first, but these days I realise its really amazing.
1
j
don't think there are any randomised data in our setup.
I mostly trust gradle, but when doing some refactoring with dependencies, I just never fully trust that gradle is catching everything, so want to be 100% sure that all tests are green
👌 1
v
instead of opening the tasks within a specific project I just go directly into
Tasks > verification > check
That is a specific project, the root project. It just seems you cannot run like
:check
or
:foo:check
, but it always runs
check
with the working directory of the selected project, so runs the task in root project and all descendents or
foo
and all descendents.
Just that you know the difference of my given commands.
--rerun-tasks
force-reruns all tasks in the task graph,
--rerun
only force-reruns the task for which it was specified. That's why with
test
you can use
--rerun
, but with
check
you need to use
--rerun-tasks
as
--rerun
would only force-rerun
check
which is useless as it has no actions anyway.
👍 2
a
IntelliJ used to forcibly break Gradle caching of test tasks, until quite recently https://youtrack.jetbrains.com/issue/IDEA-240111, and I don't think the IntelliJ UI has been updated to properly communicate that it's okay that test tasks didn't run, but under-the-hood it works fine.
v
Oh, really? I thought that was only when you say "Run test" with Gradle delegation enabled. Forgot they also did it for normal task execution.
But it at least stayed as option. So you can enable it as option in a Gradle run configuration if you are on 2023.1 or newer.
j
You can run the
cleanAllTests
task before
check
to re-run all tests without needing to
clean
the entire build.
v
Only if you have such a task. That is, only if you build a Kotlin project.
👍 1