Build with maven error

Somebody please help me out.

-----Below is my git action simple code------

name: Java CI with Maven

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
name: Unit Test
runs-on: ubuntu-20.04

steps:
  - name: setup JDK 11
    uses: actions/setup-java@v1
    with:
      java-version: 11
     
  - name: Build with Maven
    run: mvn -B package --file pom.xml

---------Below is the error that I’m getting---------

Run mvn -B package --file pom.xml
POM file pom.xml specified with the -f/–file command line argument does not exist
[INFO] Scanning for projects…
Error: ] Some problems were encountered while processing the POMs:
[FATAL] Non-readable POM /home/runner/work/webapp/webapp/pom.xml: /home/runner/work/webapp/webapp/pom.xml (No such file or directory) @
@
Error: The build could not read 1 project -> [Help 1]
Error:
Error: The project (/home/runner/work/webapp/webapp/pom.xml) has 1 error
Error: Non-readable POM /home/runner/work/webapp/webapp/pom.xml: /home/runner/work/webapp/webapp/pom.xml (No such file or directory)
Error:
Error: To see the full stack trace of the errors, re-run Maven with the -e switch.
Error: Re-run Maven using the -X switch to enable full debug logging.
Error:
Error: For more information about the errors and possible solutions, please read the following articles:
Error: [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
Error: Process completed with exit code 1.

@KrishnaSingh0109,

You should use the checkout action to check out the repository to the job’s workspace (github.workspace) on the runner machine, before building.

name: Java CI with Maven

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    name: Unit Test
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2.3.3

      - name: setup JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11

      - name: Build with Maven
        run: mvn -B package --file pom.xml

Tip: If there is any step in a job needs to access the repository files, you should set up a step in the job to check out the repository to the runner machine at first.

Thank you for the reply, I have tried as per your solution but still getting the same error.

----Below is Checkout repository----

@KrishnaSingh0109,

Make sure the file “pom.xml” is existing in your repository.

It is there.

@KrishnaSingh0109,

You provide an incorrect relative path of the file “pom.xml”.

     - name: Build with Maven
       run: mvn -B package --file pom.xml

The correct relative path should be this:

      - name: Build with Maven
        run: mvn -B package --file webapp/pom.xml

In each job of the workflow, the default working directory of all the steps is “github.workspace” (that is, GITHUB_WORKSPACE). More details, see "github context " and “Default environment variables”.

In your case, due to the “pom.xml” is in a folder under the repository’s root directory and not directly in the root directory, you should use the complete relative path of the file (webapp/pom.xml or ./webapp/pom.xml) that is relative to the root directory, instead of only the file name (“pom.xml”).

Yes, know it does read my file but still giving error of snapshot referencing itself.

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)