Share via


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.

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

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.

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. Default value: true.

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


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: 'x64'
    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
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.