Java Tool Installer task

Azure Pipelines

Use this task in a build or release pipeline to acquire a specific version of Java from a user supplied Azure blob, from a location in the source or on the agent, or from the tools cache. The task also sets the JAVA_HOME environment variable. Use this task to change the version of Java used in Java tasks.

Demands

None

YAML snippet

# Java tool installer
# Acquire a specific version of Java from a user-supplied Azure blob or the tool cache and sets JAVA_HOME
- task: JavaToolInstaller@0
  inputs:
    #versionSpec: '8' 
    jdkArchitectureOption: # Options: x64, x86
    jdkSourceOption: # Options: AzureStorage, LocalDirectory
    #jdkFile: # Required when jdkSourceOption == LocalDirectory
    #azureResourceManagerEndpoint: # Required when jdkSourceOption == AzureStorage
    #azureStorageAccountName: # Required when jdkSourceOption == AzureStorage
    #azureContainerName: # Required when jdkSourceOption == AzureStorage
    #azureCommonVirtualFile: # Required when jdkSourceOption == AzureStorage
    jdkDestinationDirectory: 
    #cleanDestinationDirectory: true 

Arguments

Argument Description
JDK Version Specify which JDK version to download and use.
JDK Architecture Specify the bit version of the JDK.
JDK source Specify the source for the compressed JDK, either Azure blob storage or a local directory on the agent or source repository.
JDK file Applicable when JDK is located in a local directory. Specify the path to the folder that contains the compressed JDK. The path could be in your source repository or a local path on the agent.
Azure Subscription Applicable when the JDK is located in Azure Blob storage. Specify the Azure Resource Manager subscription for the JDK.
Storage Account Name Applicable when the JDK is located in Azure Blob storage. Specify the Storage account name in which the JDK is located. Azure Classic and Resource Manager storage accounts are listed.
Container Name Applicable when the JDK is located in Azure Blob storage. Specify the name of the container in the storage account in which the JDK is located.
Common Virtual Path Applicable when the JDK is located in Azure Blob storage. Specify the path to the JDK inside the Azure storage container.
Destination directory Specify the destination directory into which the JDK should be extracted.
Clean destination directory Select this option to clean the destination directory before the JDK is extracted into it.
Control options See Control options.

Examples

Here's an example of getting the archive file from a local directory on Linux. The file should be an archive (.zip, .gz) of the JAVA_HOME directory so that it includes the bin, lib, include, jre, etc. directories.

  - task: JavaToolInstaller@0
    inputs:
      versionSpec: "11"
      jdkArchitectureOption: x64
      jdkSourceOption: LocalDirectory
      jdkFile: "/builds/openjdk-11.0.2_linux-x64_bin.tar.gz"
      jdkDestinationDirectory: "/builds/binaries/externals"
      cleanDestinationDirectory: true

Here's an example of downloading the archive file from Azure Storage. The file should be an archive (.zip, .gz) of the JAVA_HOME directory so that it includes the bin, lib, include, jre, etc. directories.

- task: JavaToolInstaller@0
  inputs:
    versionSpec: '6'
    jdkArchitectureOption: 'x64'
    jdkSourceOption: AzureStorage
    azureResourceManagerEndpoint: myARMServiceConnection
    azureStorageAccountName: myAzureStorageAccountName
    azureContainerName: myAzureStorageContainerName
    azureCommonVirtualFile: 'jdk1.6.0_45.zip'
    jdkDestinationDirectory: '$(agent.toolsDirectory)/jdk6'
    cleanDestinationDirectory: false

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

Q & A

Where can I learn more about tool installers?

For an explanation of tool installers and examples, see Tool installers.

Do I need an agent?

You need at least one agent to run your build or release. Get an agent for Linux, macOS, or Windows.

I'm having problems. How can I troubleshoot them?

See Troubleshoot Build and Release.

I can't select a default agent pool and I can't queue my build or release. How do I fix this?

See Agent pools.