1

I am running my job on a specific agent and using below commands

- script: |
    java -version
  env:
    JAVA_HOME: $(JAVA_HOME_11_X64)
    PATH: $(JAVA_HOME_11_X64)/bin:$(PATH)

Output

openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.18.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.18.04, mixed mode, sharing)

But when the maven command runs it doesn't find java so what exactly should I pass here. openjdk 11.0.11 is present on agent and how to pass this in maven? I tried passing 1.8 and 11.0.11 but it given error for that too. How to solve this and what exactly should I pass here in maven task?

- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    mavenOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '11'
    jdkArchitectureOption: 'x64'

Output

##[error]Unhandled: Failed to find the specified JDK version. Please ensure the specified JDK version is installed on the agent and the environment variable 'JAVA_HOME_11_X64' exists and is set to the location of a corresponding JDK or use the [Java Tool Installer](https://go.microsoft.com/fwlink/?linkid=875287) task to install the desired JDK.
Finishing: Maven



Maddy
  • 674
  • 1
  • 7
  • 26

1 Answers1

1

In Maven task, if you need to use JAVA 11 , you can try to set the jdkVersionOption to 1.11.

For example:

- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.11'
    mavenVersionOption: 'Default'

From your description, JAVA 11 has been installed on your agent.

If this issue still exists, you can configure the Pipeline variable for Java 11.

You can add a Command Line task/ PowerShell task/ Bash task to run the following command.

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

In this case, the java parameter will be set to the Pipeline global variable

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • I have added same script as part of the Command Line task I was using. I am getting error as /agent/_work/_temp/8855a05a-4b67-5644f-a0f9-132c382c4f62.sh: line 2: JAVA_HOME_11_X64: command not found /agent/_work/_temp/8855a05a-4b67-5644f-a0f9-132c382c4f62.sh: line 3: JAVA_HOME_11_X64: command not found – Maddy Oct 26 '21 at 12:42