Issue
I am trying to use diamond operator in code
HashMap<String, Integer> unsyncMap = new HashMap<>();
However, I am receiving the following error on Azure DevOps pipeline:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
##[debug]full match = /home/vsts/work/1/s/src/main/java/org/train/modules/hashmaps/HashMapping.java:[12,58] diamond
##[debug]file path = /home/vsts/work/1/s/src/main/java/org/train/modules/hashmaps/HashMapping.java
##[debug]line number = 12
##[debug]column number = 58
##[debug]message = diamond
##[error] /home/vsts/work/1/s/src/main/java/org/train/modules/hashmaps/HashMapping.java(12,58): error : /home/vsts/work/1/s/src/main/java/org/train/modules/hashmaps/HashMapping.java:[12,58] diamond
##[debug]Processed: ##vso[task.issue type=error;sourcepath= /home/vsts/work/1/s/src/main/java/org/train/modules/hashmaps/HashMapping.java;linenumber=12;columnnumber=58;] /home/vsts/work/1/s/src/main/java/org/train/modules/hashmaps/HashMapping.java:[12,58] diamond
[ERROR] /home/vsts/work/1/s/src/main/java/org/train/modules/hashmaps/HashMapping.java:[12,58] diamond operator is not supported in -source 6
(use -source 7 or higher to enable diamond operator)
The yaml is already updated to use JDK 1.11
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'compile'
Also note that the debug of maven build is showing that its using JDK 11
##[debug]Using the specified JDK version to find and set JAVA_HOME
##[debug]jdkVersion=1.11
##[debug]jdkArchitecture=x64
##[debug]Locate JAVA_HOME for Java 1.11 x64
##[debug]JAVA_HOME_11_X64=/usr/lib/jvm/zulu-11-azure-amd64
##[debug]Agent.Version=2.165.0
##[debug]Processed: ##vso[telemetry.publish area=TaskHub;feature=Maven]{"jdkVersion":"1.11"}
##[debug]set JAVA_HOME=/usr/lib/jvm/zulu-11-azure-amd64
##[debug]Processed: ##vso[task.setvariable variable=JAVA_HOME;issecret=false;]/usr/lib/jvm/zulu-11-azure-amd64
##[debug]Enabled code coverage successfully
Solution
You can configure your java version in mvn compiler plugin. In your pom it should be like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
Answered By - Eduard Dubilyer
Answer Checked By - Cary Denson (JavaFixing Admin)