gradle: Improve toolchains test
Previously the test relied on the output of the javaToolchains task and
therefore on the way that toolchains are passed to Gradle. This was
brittle in case we want to change the way of how we supply toolchains to
Gradle (see e.g. #366929).
After this change, instead of inspecting the output of javaToolchains,
the toolchains test now tries to assemble a project using a toolchain
that was passed via the gradle.override.