In several situations I have a maven based Java project that needs to be built and tested using a combination of different JDK /JRE versions.
This is especially true for projects that produce a library that is to be used by other projects.
There it is needed to verify if it can be used in several different JRE versions and thus the tests need to be compiled and run by those versions.
Within the Maven ecosystem this is handled by having all of the JDKs installed and the ~/.m2/toolchains.xml file that defines where each available JDK can be found.
Build systems like maven and gradle can all use this to have a single build which mixes various JDK versions
I want to be able to build projects like this using Gitlab-CI.
Since Gitlab-CI runs the build in a docker image I expected that there would be an image available with all current LTS JDKs (8, 11 and 17) installed that allows me run my build on (both at home, work and in the hosted Gitlab) but I have not been able to find such an image.
On Github their build system allows stacking tools relatively easily.
What is the proper way to build applications like that in Gitlab-CI?
P.S. I have created the smallest possible project to work on this: