Azure DevOps 管道错误 "diamond operator is not supported in -source 6"
Error on Azure DevOps Pipeline "diamond operator is not supported in -source 6"
我正在尝试在代码中使用菱形运算符
HashMap<String, Integer> unsyncMap = new HashMap<>();
但是,我在 Azure DevOps 管道上收到以下错误:
[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)
yaml 已更新为使用 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'
另请注意,maven 构建的调试显示其使用 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
您可以在 Maven 编译器插件中配置您的 java 版本。在你的 pom 中它应该是这样的:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
我正在尝试在代码中使用菱形运算符
HashMap<String, Integer> unsyncMap = new HashMap<>();
但是,我在 Azure DevOps 管道上收到以下错误:
[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)
yaml 已更新为使用 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'
另请注意,maven 构建的调试显示其使用 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
您可以在 Maven 编译器插件中配置您的 java 版本。在你的 pom 中它应该是这样的:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>