gradle 清泉级:src/test/resouces中的文件不可访问

332nm8kg  于 2023-01-26  发布在  其他
关注(0)|答案(1)|浏览(138)

我正在使用gradle构建Spring启动应用。集成测试(Spock)需要访问code/src/resouces/docker-composite. yml文件来准备TestContainers容器:

static DockerComposeContainer postgresContainer = new DockerComposeContainer(
        ResourceUtils.getFile("classpath:docker-compose.yml"))

git文件的结构是:

- code
  - src
    - main
    - test
      - resources
        - docker-compose.yml

这在我的本地计算机上运行得很好,但是一旦我在Azure管道中运行它,它就会给出

No such file or directory: '/__w/1/s/code/build/resources/test/docker-compose.yml'

我的管道yaml就像bellow一样,我使用Ubuntu容器和Java17,因为我需要用17来构建,但是Azure的最新版本是11(也许这在我得到的错误中起了什么作用?)

trigger: none

stages:
  - stage: Test
    displayName: Test Stage
    jobs:
      - job: Test
        pool:
          vmImage: 'ubuntu-22.04'
        container: gradle:7.6.0-jdk17
        variables:
          - name: JAVA_HOME_11_X64
            value: /opt/java/openjdk
        displayName: Test
        steps:
          - script: java --version
            displayName: Java version
          - script: |
              echo "Build reason is: $(Build.Reason)"
            displayName: Build reason
          - checkout: self
            clean: true
          - task: Gradle@2
            displayName: 'Gradle Build'
            enabled: True
            inputs:
              javaHomeSelection: 'path'
              jdkDirectory: '/opt/java/openjdk'
              wrapperScript: code/gradlew
              cwd: code
              tasks: clean build
              publishJUnitResults: true
              jdkVersionOption: 1.17

多谢帮忙!

q35jwt9p

q35jwt9p1#

我已经通过"变通"解决了这个问题-我意识到我不需要使用jdk17的容器,这是导致问题(当然不能访问主机上的文件)事实是Azure通过指令静默支持Jkd17:* * jdk版本选项:1.17**
但是,一旦有人需要使用容器构建代码并访问不在类路径上的存储库文件,问题就会再次出现

trigger: none

stages:
  - stage: Test
    displayName: Test Stage
    jobs:
      - job: Test
        pool:
          vmImage: 'ubuntu-22.04'
        displayName: Test
        steps:
          - script: java --version
            displayName: Java version
          - script: |
              echo "Build reason is: $(Build.Reason)"
            displayName: Build reason
          - checkout: self
            clean: true
          - task: Gradle@2
            displayName: 'Gradle Build'
            enabled: True
            inputs:
              wrapperScript: server/code/gradlew
              cwd: server/code
              tasks: test
              publishJUnitResults: true
              jdkVersionOption: 1.17

详情请关注Azure pipeline issue

相关问题