1

I spent hours to find out, why one of my junit tests runs local but not on the github workflow. 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. Here is my plugin setting of my 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.

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.

Any hints?

UPDATE:

Just testet, mvn clean test fails on github workflow too!

double-beep
  • 5,031
  • 17
  • 33
  • 41
Thilo Schwarz
  • 640
  • 5
  • 24
  • Why the **UPDATE**? Isn't this the same as in the sentence after the POM excerpt? – Gerold Broser Nov 27 '21 at 23:33
  • 1
    You're saying that "mvn clean test" is failing on github, but this file you're showing here is specifying how to run the sonarqube scan. The two things don't appear to have anything to do with each other. How about you show us exactly what happens when "mvn clean test" runs on github? – David M. Karr Nov 28 '21 at 00:01
  • 1
    You haven't explained what actual failure the test gets, or shown the test code. – tgdavies Nov 28 '21 at 00:57
  • Sorry for wasting your time and thank you all for leading me in right direction. At first I thought, it's an issue of the sonar maven plugin, then I realize "mvn test" fails too. That was the reason for the UPDATE. But as so often, the problem was between my ears. You should stop when it becomes too much and continue the next day ... It was just a wrong setting in my test environment! – Thilo Schwarz Nov 28 '21 at 10:36

1 Answers1

2

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:

The Resources Plugin handles the copying of project resources to the output directory. 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.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107