Azure Pipeline 与 SpringBoot 和 Gradle 失败

问题描述 投票:0回答:1

您好,我在 Azure 管道中运行 Snyk 安全分析,出现以下错误,我尝试搜索解决方案,但找不到任何解决方案。可能是什么?下面你可以找到错误和我的 pipeline.yaml

 > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.1.6.
 Required by:
     project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.1.6
  > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.1.6 
 was found. The consumer was configured to find a library for use during runtime, compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.5' but:
      - Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.6 declares a library, packaged as a jar, and its dependencies declared externally:
          - Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 11
          - Other compatible attribute:
              - Doesn't say anything about org.gradle.plugin.api-version (required '8.5')
      - Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.6 declares a component for use during runtime, and its dependencies declared externally:
          - Incompatible because this component declares documentation and the consumer needed a library
          - Other compatible attributes:
              - Doesn't say anything about its target Java version (required compatibility with Java 11)
              - Doesn't say anything about its elements (required them packaged as a jar)
              - Doesn't say anything about org.gradle.plugin.api-version (required '8.5')
      - Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.1.6 declares a library, packaged as a jar, and its dependencies declared externally:
          - Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 11
          - Other compatible attribute:
              - Doesn't say anything about org.gradle.plugin.api-version (required '8.5')
      - Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.1.6 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
          - Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11
          - Other compatible attribute:
              - Doesn't say anything about org.gradle.plugin.api-version (required '8.5')
      - Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.6 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
          - Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11
          - Other compatible attribute:
              - Doesn't say anything about org.gradle.plugin.api-version (required '8.5')
      - Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.6 declares a component for use during runtime, and its dependencies declared externally:
          - Incompatible because this component declares documentation and the consumer needed a library
          - Other compatible attributes:
              - Doesn't say anything about its target Java version (required compatibility with Java 11)
              - Doesn't say anything about its elements (required them packaged as a jar)
              - Doesn't say anything about org.gradle.plugin.api-version (required '8.5')

这是我的管道 cong yaml,看起来我正确设置了 jvm,但在运行的作业日志中我看到了 gradle jvm 11:

   variables:
   - name: projectName
    value: 'reports'
   - name: jdkVersion
    value: '17'
   - name: GIT_COMMIT_ID
    value: $(Build.SourceVersion)
   - name: SNYK_API
    value: https://app.eu.snyk.io/api/
   trigger:
    branches:
     include:
     - master

 resources:
   repositories:
  - repository: azure-pipelines-templates
    type: git
    name: "name/azure-pipelines-templates"
    ref: refs/tags/v10

 pool:
  vmImage: 'ubuntu-latest'

 steps:
  - script: echo "##vso[task.setvariable variable=ComponentVersion]$(./gradlew -q :printVersion)"
  displayName: Get Component Version

 - template: gradle/gradle_ci.yaml@azure-pipelines-templates
   parameters:
    jdkVersion: $(jdkVersion)
    sonarServiceConnection: 'sonarCloud.service.connection'
    sonarProjectKey: 'reports'
    sonarProjectName: 'expense-reports'
    containerRegistry: 'docker.registry'
    containerRegistryUrl: 'registrysharedinternalapps.azurecr.io'
    dockerRepository: $(projectName)
    dockerTag: $(ComponentVersion)-${{ variables.GIT_COMMIT_ID }}
    skipTests: false
    codeCoverageToolOption: none
    useGradleToBuildDockerImage: false
    dockerBuildAndPush: true
    testTasks: build
    snykSkip: false
    snykServiceConnectionName: 'snyk_eu_service_connection'
    snykOrgUrlName: 'openwt-internal-projects'
    snykTasks:
    - snykFailOnIssues: false
    snykAdditionalArguments: '-d --all-projects -exclude=build.gradle'
    - snykFailOnIssues: false
    snykTargetFile: 'build.gradle'
    snykProjectName: 'expense-report'
    snykAdditionalArguments: '-d'
java spring-boot azure gradle pipeline
1个回答
0
投票

谢谢你@M。 Deinum 供您评论:-

请参阅我的SO答案

Java version 17
安装为
ubuntu-latest
Microsoft托管代理Azure Devops默认不支持Java版本11以上。

我的yaml代码:-

jobs:
- job: Build
  pool:
    vmImage: 'ubuntu-latest'

  steps:
  - task: JavaToolInstaller@0
    inputs:
      versionSpec: '17'
      jdkArchitectureOption: 'x64'
      jdkSourceOption: 'PreInstalled'

  - script: |
      echo "Setting JAVA_HOME to JDK 17 location."
      java -version
    displayName: 'Check Java Version'

输出:-

enter image description here

您更新的

yaml code
将如下所示,其中
JavaToolInstaller@0
任务:-

variables:
  - name: projectName
    value: 'reports'
  - name: jdkVersion
    value: '17'
  - name: GIT_COMMIT_ID
    value: $(Build.SourceVersion)
  - name: SNYK_API
    value: https://app.eu.snyk.io/api/

trigger:
  branches:
    include:
      - master

resources:
  repositories:
    - repository: azure-pipelines-templates
      type: git
      name: "name/azure-pipelines-templates"
      ref: refs/tags/v10

pool:
  vmImage: 'ubuntu-latest'

steps:
  - task: JavaToolInstaller@0
    inputs:
      versionSpec: '17'
      jdkArchitectureOption: 'x64'
      jdkSourceOption: 'PreInstalled'

  - script: |
      echo "Setting JAVA_HOME to JDK 17 location."
      java -version
    displayName: 'Check Java Version'

  - script: echo "##vso[task.setvariable variable=ComponentVersion]$(./gradlew -q :printVersion)"
    displayName: 'Get Component Version'

  - template: gradle/gradle_ci.yaml@azure-pipelines-templates
    parameters:
      jdkVersion: $(jdkVersion)
      sonarServiceConnection: 'sonarCloud.service.connection'
      sonarProjectKey: 'reports'
      sonarProjectName: 'expense-reports'
      containerRegistry: 'docker.registry'
      containerRegistryUrl: 'registrysharedinternalapps.azurecr.io'
      dockerRepository: $(projectName)
      dockerTag: $(ComponentVersion)-${{ variables.GIT_COMMIT_ID }}
      skipTests: false
      codeCoverageToolOption: none
      useGradleToBuildDockerImage: false
      dockerBuildAndPush: true
      testTasks: build
      snykSkip: false
      snykServiceConnectionName: 'snyk_eu_service_connection'
      snykOrgUrlName: 'openwt-internal-projects'
      snykTasks:
        - snykFailOnIssues: false
          snykAdditionalArguments: '-d --all-projects -exclude=build.gradle'
        - snykFailOnIssues: false
          snykTargetFile: 'build.gradle'
          snykProjectName: 'expense-report'
          snykAdditionalArguments: '-d'
© www.soinside.com 2019 - 2024. All rights reserved.