Java Tool Installer task

Azure DevOps Services

Use this task 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
versionSpec
JDK Version
(Required) Specify which JDK version to download and use.
Default value: 8
jdkArchitectureOption
JDK Architecture
(Required) Specify the bit version of the JDK.
Options: x64, x86
jdkSourceOption
JDK source
(Required) Specify the source for the compressed JDK, either Azure blob storage or a local directory on the agent or source repository or use the pre-installed version of Java (available for Microsoft-hosted agents). Please see example below about how to use pre-installed version of Java
jdkFile
JDK file
(Required) Applicable when jdkSourceOption == LocalDirectory. Specify 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 bin folder either on the root level or inside a single directory. For macOS - there's support of .pkg and .dmg files containing only one .pkg file inside.
azureResourceManagerEndpoint
Azure Subscription
(Required) Applicable when jdkSourceOption == AzureStorage. Specify the Azure Resource Manager subscription for the JDK.
azureStorageAccountName
Storage Account Name
(Required) Applicable when jdkSourceOption == AzureStorage. Specify the Storage account name in which the JDK is located. Azure Classic and Resource Manager storage accounts are listed.
azureContainerName
Container Name
(Required) Applicable when jdkSourceOption == AzureStorage. Specify the name of the container in the storage account in which the JDK is located.
azureCommonVirtualFile
Common Virtual Path
(Required) Applicable when jdkSourceOption == AzureStorage. Specify the path to the JDK inside the Azure storage container.
jdkDestinationDirectory
Destination directory
(Required) Specify the destination directory into which the JDK should be installed (only for Windows and Linux). On macOS, this directory is used as a temporary folder for extracting of .dmg's since macOS doesn't support installing of JDK to specific directory.
cleanDestinationDirectory
Clean destination directory
(Required) Select this option to clean the destination directory before the JDK is extracted into it.
Default value: true

Note

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

  1. Run sudo visudo command, it will open sudoers file for editing.
  2. Go to the bottom of the file and add the following line: user ALL=NOPASSWD: /usr/sbin/installer (Replace 'user' by 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 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

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 Software section.

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

Open source

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

FAQ

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.

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.

My NuGet push task is failing with the following error: "Error: unable to get local issuer certificate". How can I fix this?

This can be fixed by adding a trusted root certificate. You can either add the NODE_EXTRA_CA_CERTS=file environment variable to your build agent, or you can add the NODE.EXTRA.CA.CERTS=file task variable in your pipeline. See Node.js documentation for more details about this variable. See Set variables in a pipeline for instructions on setting a variable in your pipeline.