Is there anything for Java getting close to this?
Test with the Python installer task
, this task is used to specify a specific python version via setting the environment.
To achieve a similar purpose with Java, you could set the Java_Home
and Path
variable during the runtime.
You could add a powershell task at the first step.
Here is an example:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
echo "##vso[task.setvariable variable=JAVA_HOME]$(JAVA_HOME_11_X64)"
echo "##vso[task.setvariable variable=PATH]$(JAVA_HOME_11_X64)\bin;$(PATH)"
The $(JAVA_HOME_11_X64)
variable is an environment variable.
You could check this variable with the script env | sort
. Then the supported value will list in the output.
For example:

In this case, the JAVA_HOME variable will be set as the expected value.

Hope this helps.