簡體   English   中英

Azure DevOps Pipeline 上的錯誤“-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 build 的調試顯示它使用的是 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

您可以在 mvn 編譯器插件中配置您的 java 版本。 在你的 pom 中它應該是這樣的:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM