[英]github workflows: maven tests fail when because of missing some test resources, but runs local
I spent hours to find out, why one of my junit tests runs local but not on the github workflow.我花了几个小时来找出为什么我的 junit 测试之一在本地运行,但不在 github 工作流程上运行。 The test which fails checks the existence of some files to do some configuration stuff.失败的测试检查是否存在一些文件来做一些配置工作。 I'm using the maven-resources-plugin to copy these files to a folder inside the target directory.我正在使用 maven-resources-plugin 将这些文件复制到目标目录内的文件夹中。 Here is my plugin setting of my pom.xml:这是我的 pom.xml 的插件设置:
<plugin>
<!-- move some test resources to target -->
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resource-one</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/test-dir</outputDirectory>
<resources>
<resource>
<directory>${basedir}/test-files</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
The files are copied as expected and mvn clean test
runs as expected, but not within a github workflow.文件按预期复制,并且mvn clean test
按预期运行,但不在 github 工作流程中。
Here is my workflow definition:这是我的工作流程定义:
name: Sonar Scan
on:
push:
branches:
- develop
- feature*
- master
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2.3.1
with:
distribution: 'adopt'
java-version: '11'
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=abckey
I guess this is a typically RTFM problem, but I didn't find anything.我想这是一个典型的 RTFM 问题,但我什么也没找到。
Any hints?有什么提示吗?
UPDATE:更新:
Just testet, mvn clean test
fails on github workflow too!只是 testet, mvn clean test
在 github 工作流程上也失败了!
You don't need to copy test resource files to target[/sub/dir]
explicitely if you place them in src/test/resources[/sub/dir]
the Maven Resources Plugin is bound to the process-resources
and process-test-resources
phases by default and hence does this for you without any declaration in the POM:如果将测试资源文件放在src/test/resources[/sub/dir]
中,则不需要process-test-resources
process-resources
资源文件显式复制到target[/sub/dir]
process-test-resources
默认为阶段,因此无需在 POM 中进行任何声明即可为您执行此操作:
The Resources Plugin handles the copying of project resources to the output directory. Resources Plugin 处理将项目资源复制到 output 目录。 There are two different kinds of resources: main resources and test resources.有两种不同的资源:主要资源和测试资源。 The difference is that the main resources are the resources associated to the main source code while the test resources are associated to the test source code.区别在于主要资源是与主要源代码相关联的资源,而测试资源与测试源代码相关联。
Thus, this allows the separation of resources for the main source code and its unit tests.因此,这允许主要源代码及其单元测试的资源分离。
Not that this is the reason for your issue but I'd remove the declaration from the POM anyway.并不是这就是您的问题的原因,但无论如何我都会从 POM 中删除声明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.