Azure Pipeline - invalid target release: 11

Viewed 2596

I am setting up a pipeline for the spring-boot app with JDK 11. Getting below error while running the pipeline.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project xxxxx: Fatal error compiling: invalid target release: 11 -> [Help 1].

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>11</source>
                <target>11</target>
                <verbose>true</verbose>
            </configuration>
        </plugin>

But this is working fine local deploy command: mvn clean package spring-boot:run.

Can anyone tell me why this issue is happening only in pipeline?

4 Answers

This issue is because your pipeline agent does not have Java 11 pre-installed in it.

You have two options to solve this issue.

Option 1: Change the pipeline agent to an agent which does have Java 11 pre-installed.

If you are using Microsoft-hosted pipeline agents, you can use this link to check which all agents have Java 11 pre-installed: Microsoft-hosted agents

Option 2: Install the Java 11 JDK in your existing pipeline agent.

You can use the Java Tool Installer task to install any Java version on your existing pipeline.

Perhaps the JDK running in your pipeline is, say, version 8. In that case, the Java compiler that is executed doesn't understand what version 11 means. Perhaps your local environment is using Java 11 where this problem would therefore not happen.

I had the same problem. You need to specify the jdk version in the pipeline .yaml-file:

To build with Maven, add the following snippet to your azure-pipelines.yml file. Change values, such as the path to your pom.xml file, to match your project configuration. See the Maven task for more about these options.

steps:
- task: Maven@3   inputs:
    mavenPomFile: 'pom.xml'
    mavenOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.11'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: false
    testResultsFiles: '**/TEST-*.xml'
    goals: 'package'

https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/java?view=azure-devops#maven

I solved this problem by adding a new file system.properties and the content added to the file is java.runtime.version=11.

java.runtime.version=11
Related