JavaToolInstaller@0 - Java tool installer v0 task

Use this task to acquire a specific version of Java from a user-supplied Azure blob or the tool cache and set JAVA_HOME.

Syntax

# Java tool installer v0
# 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' # string. Required. JDK version. Default: 8.
    jdkArchitectureOption: # 'x64' | 'x86'. Required. JDK architecture. 
    jdkSourceOption: # 'AzureStorage' | 'LocalDirectory' | 'PreInstalled'. Required. JDK source. 
    #jdkFile: # string. Required when jdkSourceOption == LocalDirectory. JDK file. 
    #azureResourceManagerEndpoint: # string. Required when jdkSourceOption == AzureStorage. Azure subscription. 
    #azureStorageAccountName: # string. Required when jdkSourceOption == AzureStorage. Storage account name. 
    #azureContainerName: # string. Required when jdkSourceOption == AzureStorage. Container name. 
    #azureCommonVirtualFile: # string. Required when jdkSourceOption == AzureStorage. Common virtual path. 
    #jdkDestinationDirectory: # string. Required when jdkSourceOption != PreInstalled. Destination directory. 
    #cleanDestinationDirectory: true # boolean. Required when jdkSourceOption != PreInstalled. Clean destination directory. Default: true.
    #createExtractDirectory: true # boolean. Optional. Use when jdkSourceOption != PreInstalled. Create directory for extracting. Default: true.
# Java tool installer v0
# 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' # string. Required. JDK version. Default: 8.
    jdkArchitectureOption: # 'x64' | 'x86'. Required. JDK architecture. 
    jdkSourceOption: # 'AzureStorage' | 'LocalDirectory' | 'PreInstalled'. Required. JDK source. 
    #jdkFile: # string. Required when jdkSourceOption == LocalDirectory. JDK file. 
    #azureResourceManagerEndpoint: # string. Required when jdkSourceOption == AzureStorage. Azure subscription. 
    #azureStorageAccountName: # string. Required when jdkSourceOption == AzureStorage. Storage account name. 
    #azureContainerName: # string. Required when jdkSourceOption == AzureStorage. Container name. 
    #azureCommonVirtualFile: # string. Required when jdkSourceOption == AzureStorage. Common virtual path. 
    #jdkDestinationDirectory: # string. Required when jdkSourceOption != PreInstalled. Destination directory. 
    #cleanDestinationDirectory: true # boolean. Required when jdkSourceOption != PreInstalled. Clean destination directory. Default: true.
# Java tool installer v0
# 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' # string. Required. JDK version. Default: 8.
    jdkArchitectureOption: # 'x64' | 'x86'. Required. JDK architecture. 
    jdkSourceOption: # 'AzureStorage' | 'LocalDirectory'. Required. JDK source. 
    #jdkFile: # string. Required when jdkSourceOption == LocalDirectory. JDK file. 
    #azureResourceManagerEndpoint: # string. Required when jdkSourceOption == AzureStorage. Azure subscription. 
    #azureStorageAccountName: # string. Required when jdkSourceOption == AzureStorage. Storage account name. 
    #azureContainerName: # string. Required when jdkSourceOption == AzureStorage. Container name. 
    #azureCommonVirtualFile: # string. Required when jdkSourceOption == AzureStorage. Common virtual path. 
    jdkDestinationDirectory: # string. Required. Destination directory. 
    cleanDestinationDirectory: true # boolean. Required. Clean destination directory. Default: true.
# Java Tool Installer v0
# Acquires a specific version of Java from a user supplied Azure blob or the tools cache and sets JAVA_HOME. Use this task to change the version of Java used in Java tasks.
- task: JavaToolInstaller@0
  inputs:
    versionSpec: '8' # string. Required. JDK version. Default: 8.
    jdkArchitectureOption: # 'x64' | 'x86'. Required. JDK architecture. 
    jdkSourceOption: # 'AzureStorage' | 'LocalDirectory'. Required. JDK source. 
    #jdkFile: # string. Required when jdkSourceOption == LocalDirectory. JDK file. 
    #azureResourceManagerEndpoint: # string. Required when jdkSourceOption == AzureStorage. Azure subscription. 
    #azureStorageAccountName: # string. Required when jdkSourceOption == AzureStorage. Storage account name. 
    #azureContainerName: # string. Required when jdkSourceOption == AzureStorage. Container name. 
    #azureCommonVirtualFile: # string. Required when jdkSourceOption == AzureStorage. Common virtual path. 
    jdkDestinationDirectory: # string. Required. Destination directory. 
    cleanDestinationDirectory: true # boolean. Required. Clean destination directory. Default: true.
# YAML Syntax is not supported in TFS 2018.
# Use the classic designer to add and configure tasks.
# See the following Inputs section for details on the inputs that this task supports.

Inputs

versionSpec - JDK version
string. Required. Default value: 8.

Specifies the JDK version to make available on the path. Use a whole number version, such as 10.


jdkArchitectureOption - JDK architecture
string. Required. Allowed values: x64, x86.

Specifies the architecture (x86, x64) of the JDK.


jdkSourceOption - JDK source
string. Required. Allowed values: AzureStorage (Azure Storage), LocalDirectory (Local Directory), PreInstalled (Pre-installed).

Specifies the source for the compressed JDK. The source can be Azure blob storage or a local directory on the agent or source repository, or you can use the pre-installed version of Java (available for Microsoft-hosted agents). Please see the example below about how to use the pre-installed version of Java.


jdkSourceOption - JDK source
string. Required. Allowed values: AzureStorage (Azure Storage), LocalDirectory (Local Directory).

Specifies the source for the compressed JDK. The source can be Azure blob storage or a local directory on the agent or source repository, or you can use the pre-installed version of Java (available for Microsoft-hosted agents). Please see the example below about how to use the pre-installed version of Java.


jdkFile - JDK file
string. Required when jdkSourceOption == LocalDirectory.

Specifies the path to the JDK archive file that contains the compressed JDK. The path could be in your source repository or a local path on the agent. The file should be an archive (.zip, .tar.gz, .7z) containing the bin folder on the root level or inside a single directory. MacOS supports .pkg and .dmg files containing only one .pkg file inside.


azureResourceManagerEndpoint - Azure subscription
string. Required when jdkSourceOption == AzureStorage.

Specifies the Azure Resource Manager subscription for the JDK.


azureStorageAccountName - Storage account name
string. Required when jdkSourceOption == AzureStorage.

Specifies Azure Classic or Resource Manager storage accounts. Select the storage account name in which the JDK is located.


azureContainerName - Container name
string. Required when jdkSourceOption == AzureStorage.

Specifies the name of the container in the storage account where the JDK is located.


azureCommonVirtualFile - Common virtual path
string. Required when jdkSourceOption == AzureStorage.

Specifies the path to the JDK inside the Azure storage container.


jdkDestinationDirectory - Destination directory
string. Required when jdkSourceOption != PreInstalled.

Specifies the destination directory where the JDK should be extracted. On Linux and Windows, this is used as the destination directory for the JDK installation. On macOS, this directory is used as a temporary folder for extracting .dmg's because macOS doesn't support installing JDK to a specific directory.


jdkDestinationDirectory - Destination directory
string. Required.

Specifies the destination directory where the JDK should be extracted. On Linux and Windows, this is used as the destination directory for the JDK installation. On macOS, this directory is used as a temporary folder for extracting .dmg's because macOS doesn't support installing JDK to a specific directory.


cleanDestinationDirectory - Clean destination directory
boolean. Required when jdkSourceOption != PreInstalled. Default value: true.

Specifies the option to clean the destination directory before JDK is extracted into it.


cleanDestinationDirectory - Clean destination directory
boolean. Required. Default value: true.

Specifies the option to clean the destination directory before JDK is extracted into it.


createExtractDirectory - Create directory for extracting
boolean. Optional. Use when jdkSourceOption != PreInstalled. Default value: true.

By default, the task creates a directory similar to JAVA_HOME_8_X64_OpenJDK_zip for extracting JDK. This option disables the creation of that folder and, if set to false, JDK is located in the root of jdkDestinationDirectory instead.


Task control options

All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.

Output variables

None.

Remarks

Use this task to acquire a specific version of Java from a user-supplied Azure blob, a location in the source or on the agent, or 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.

Note

To run the Java Tool Installer task on macOS, it is required for the user under which the agent is running to have permission to execute the sudo command without a password. You can follow the next steps to enable this permission:

  1. Run the sudo visudo command. The sudoers file opens for editing.
  2. Go to the bottom of the file and add the following line: user ALL=NOPASSWD: /usr/sbin/installer (Replace user with the actual user alias).
  3. Save and close the file.

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 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 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

Here's an example of using "pre-installed" feature. This feature allows you to use Java versions that are pre-installed on the Microsoft-hosted agent. You can find available pre-installed versions of Java in the included software column in the hosted agents table.

- task: JavaToolInstaller@0
  inputs:
    versionSpec: '8'
    jdkArchitectureOption: 'x86'
    jdkSourceOption: 'PreInstalled'

Requirements

Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands None
Capabilities Running this task satisfies the following demands for any subsequent tasks in the same job: Java, JDK
Command restrictions This task runs using the following command restrictions: restricted
Settable variables This task has permission to set the following variables: PATH, JAVA_HOME*
Agent version 2.182.1 or greater
Task category Tool
Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands None
Capabilities Running this task satisfies the following demands for any subsequent tasks in the same job: Java, JDK
Command restrictions Any
Settable variables Any
Agent version All supported agent versions.
Task category Tool
Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands None
Capabilities Running this task satisfies the following demands for any subsequent tasks in the same job: Java
Command restrictions Any
Settable variables Any
Agent version All supported agent versions.
Task category Tool

See also

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