'Post process antlr maven goal
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>
Solution 1:[1]
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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andrei Filipchyk |
