You can now also use the JavaToolInstaller task to activate one of the pre-installed Java versions, e.g.
- task: JavaToolInstaller@0
inputs:
versionSpec: '11'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'PreInstalled'
See documentation at:
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/java-tool-installer?view=azure-devops
It will also set JAVA_HOME and prepend the PATH, see source:
https://github.com/microsoft/azure-pipelines-tasks/blob/46cca412451ac4418d6332114fca8ef8c3095de1/Tasks/JavaToolInstallerV0/javatoolinstaller.ts#L80