Issue
I'm not quite sure why this is happening, as it didn't happen on my other project with a nearly identical setup. I'm working on a Java project with Maven and want to run my test suite upon pushing the code to rel="nofollow noreferrer">GitHub. I can do a mvn compile test -Dtest=InterpreterTester
and it will work fine locally. If, however, I push the code to GitHub, the build test fails with a bunch of cannot find symbol
errors and package x does not exist.
Again, this doesn't happen locally and I've used a similar setup in a previous project (in fact, the .yml file was copied verbatim and the .pom file only differs in the version of ANTLR). Can anyone see what might be going wrong?
maven.yml
file:
name: tests
on: push
jobs:
run_tests:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Set up JDK 14
uses: actions/setup-java@v1
with:
java-version: 14
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Run tests with Maven
run: mvn compile test -Dtest=InterpreterTester
Solution
Fixed it on my own - turns out that, with ANTLR and Maven, the .g4
file must be inside a package of the same "name" as the rest of the project. For instance, my .g4
file was inside src/main/antlr4/mygrammar.g4
, when it should have been in src/main/antlr4/com/myproject/mygrammar.g4
because the rest of the project's structure is src/main/java/com/myproject/...
.
This, in turn, allows Maven to recognize the grammar location and generate the correct files with mvn clean compile
.
Answered By - TheProgrammer
Answer Checked By - Gilberto Lyons (JavaFixing Admin)