Home > Software design >  Eclipse with ANTLR4 IDE add-on automatically builds with ANTLR 4.4
Eclipse with ANTLR4 IDE add-on automatically builds with ANTLR 4.4

Time:10-23

I'm trying to work on an ANTLR 4.9.2 project using Eclipse and Maven. I have configured my pom.xml to use the correct version of the runtime and build tools:

<properties>
    <maven.compiler.target>18</maven.compiler.target>
    <maven.compiler.source>18</maven.compiler.source>
    <antlr4.plugin.version>4.9.2</antlr4.plugin.version>
    <antlr4.version>4.9.2</antlr4.version>
</properties>

<dependencies>
    <!-- ANTLR 4 parser runtime -->
    <dependency>
        <groupId>org.antlr</groupId>
        <artifactId>antlr4-runtime</artifactId>
        <version>${antlr4.version}</version>
    </dependency>

    <!-- ANTLR 4 parser generator tools -->
    <dependency>
        <groupId>org.antlr</groupId>
        <artifactId>antlr4-maven-plugin</artifactId>
        <version>${antlr4.plugin.version}</version>
    </dependency>
    <!-- other irrelevant dependencies redacted -->
</dependencies>
<build>
    <plugins>
        <!-- build antlr4 grammars -->
        <plugin>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-maven-plugin</artifactId>
            <version>${antlr4.plugin.version}</version>
            <configuration>
                <arguments>
                    <argument>-visitor</argument>
                    <!-- <argument>-Dlanguage=JavaScript</argument> -->
                </arguments>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>antlr4</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <!-- ensure antlr4 generated source is added to the build path -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${project.build.directory}/generated-sources/antlr4/</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I have also installed the ANTLR4IDE eclipse add-on (reported as ANTLR 4 SDK 0.3.6.201611052310 antlr4ide.sdk.feature.group Edgar Espina in the Installation Details screen) in order to provide syntax highlighting when editing .g4 files.

The issue I have is that every time I modify a file, this appears in the console window:

ANTLR Tool v4.4 (C:\Users\user\AppData\Local\Temp\antlr-4.4-complete.jar)
KindModule.g4 -o C:\Users\user\git\kindtest3\target\generated-sources\antlr4\org\kindlang\kindtest3\grammar -listener -no-visitor -package org.kindlang.kindtest3.grammar -encoding UTF-8

BUILD SUCCESSFUL
Total time: 4 second(s)

and running the project tests fails with the error message ANTLR Tool version 4.4 used for code generation does not match the current runtime version 4.9.2

I have tried to disable the setting "Tool is activated" under "Project properties / ANTLR4 / Tool", but this only seems to disable it for the current session. When I restart Eclipse it starts happening again.

(Updated -- in fact, there seems to be a bug in the properties dialog: when I click "apply & close", a message box with the title "Error" is briefly displayed but then disappears before I can read its contents)

How can I permanently prevent this automatic build that is using the wrong version of ANTLR from running?

CodePudding user response:

Unfortunately I can not say something about Eclipse.

I would suggest to use the antlr4-maven-plugin in the correct way like this:

  <build>
    <plugins>
      <plugin>
        <groupId>org.antlr</groupId>
        <artifactId>antlr4-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>antlr4</goal>
            </goals>
            <configuration>
              <visitor>true</visitor>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

Furthermore the configuration to use build-helper-maven-plugin is simply superflous because the antlr4-maven-plugin correctly adds the information to be compiled. This means remove the whole configuration and definition for build-helper-maven-plugin because it is not needed at all.

Also I would suggest to upgrade to the most recent version of antlr4-maven-plugin / runtime which 4.11.1 at the moment...

I would check the compilation etc. on plain command line.

CodePudding user response:

I have been able to solve the problem by directly editing the com.github.jknack.antlr4ide.Antlr4.prefs file in the .settings directory under my project root and changing the line autobuilding=true to autobuilding=false.

  • Related