Post process antlr maven goal

125 views Asked by At

I'm running antlr with maven. Antlr generates .java file from .g file and I need to post process generated java file (do some changes in it). How can I do it?

<plugin>
            <groupId>org.antlr</groupId>
            <artifactId>antlr3-maven-plugin</artifactId>
            <version>3.5.2</version>
            <configuration>
                <outputDirectory>src/main/java</outputDirectory>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>antlr</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
1

There are 1 answers

0
Andrei Filipchyk On

Finally I've found a solution. You have to use maven-antrun-plugin, it can execute java code. Another problem was that there were no compiled classes yet in the process-sources phase (you need to run it before compile). So before executing the java class, you need to compile it or do as I did - store the already compiled class and copy it to target classes.

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <copy file="path\to\LogicsParserPostProcess.class"
                                      tofile="path\to\target\classes\LogicsParserPostProcess.class" />
                                <java classname="LogicsParserPostProcess" failonerror="true">
                                    <classpath refid="maven.compile.classpath"/>
                                </java>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>