[antlr-interest] Maven vs AntlrWorks Generated Sources
Luca Li Greci
luca.ligreci at gmail.com
Tue Sep 29 12:35:04 PDT 2009
2009/9/27 Ramirez, Paul M (388J) <paul.m.ramirez at jpl.nasa.gov>
> Hi All,
>
> I’m having an issue when generating java sources in Maven versus with
> AntlrWorks. AntlrWorks seems to generate a perfectly fine size parser and
> lexer but in Maven the source code gets bloated to the point that it won’t
> compile. We are using a helper plugin to compile other source files with the
> generated sources. Below is the applicable portions of the pom file. I’m
> hoping it’s just a configuration I can change. If there is anything else I
> could provide to help resolve this issue please let me know.
>
> <plugin>
> <groupId>org.codehaus.mojo</groupId>
>
> <artifactId>build-helper-maven-plugin</artifactId>
> <version>1.0</version>
> <executions>
> <execution>
> <id>add-source</id>
>
> <phase>generate-sources</phase>
> <goals>
>
> <goal>add-source</goal>
> </goals>
> <configuration>
> <sources>
>
> <source>target/generated-sources/antlr3</source>
> </sources>
> </configuration>
> </execution>
> </executions>
> </plugin>
>
> <plugin>
> <groupId>org.antlr</groupId>
>
> <artifactId>antlr3-maven-plugin</artifactId>
> <version>3.1.3-1</version>
>
> <executions>
> <execution>
>
> <phase>generate-sources</phase>
> <goals>
> <goal>antlr</goal>
> </goals>
> </execution>
> </executions>
>
> </plugin>
>
> <dependency>
> <groupId>org.antlr</groupId>
> <artifactId>antlr-runtime</artifactId>
> <version>3.1.3</version>
> </dependency>
> <dependency>
> <groupId>org.antlr</groupId>
> <artifactId>stringtemplate</artifactId>
> <version>3.2</version>
> </dependency>
>
>
>
> Thanks,
> Paul Ramirez
> Senior Computer Scientist
> Jet Propulsion Laboratory
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
Hi Paul,
I don't understand what exactly happened with your pom file. Here is what I
defined in mine
In the dependecies section
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<version>3.1.3-1</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
<version>3.2</version>
<exclusions>
<exclusion>
<artifactId>antlr</artifactId>
<groupId>antlr</groupId>
</exclusion>
</exclusions>
</dependency>
For the compiler plugin, source and target are set to 1.6 instead of 6
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
and then
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<version>3.1.3-1</version>
<executions>
<execution>
<id>parser</id>
<phase>generate-sources</phase>
<goals>
<goal>antlr</goal>
</goals>
<configuration>
<sourceDirectory>src/main/resources/antlr3</sourceDirectory>
<libDirectory>src/main/resources/antlr3*
/org/mycompany/myproduct*</libDirectory>
<outputDirectory>target/generated-sources/antlr3</outputDirectory>
<includes>
<include>***/myGrammar*.g*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
As you can see under src/main/resources/antlr3 I created a "package
structure" of subfolder and inside myproduct I put all my grammars.
In this way I keep in synch what is generated as subdirectories with what I
declared inside the grammar file, for instance
@parser::header {package org.mycompany.myproduct;}
If you don't do that you have a weird situation where the code is generate
in the default package (top level), and in the code there's the package
definition.... it doesn't compile.
Best regards
Luca
--
Victor Hugo wrote, “The future has many names: For the weak, it means the
unattainable. For the fearful, it means the unknown. For the courageous, it
means opportunity.”
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090929/e7f6c8fe/attachment.html
More information about the antlr-interest
mailing list