If it is installed on the runner and if the workflow is running on the same runner, it should detect but I would suggest you to add setup-java job right before running actual tests
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'