1

I have the problem that maven does not compile any .g4 files and I have no clue why. I had a look at a couple of websites but since there is not a really good documentation, I cannot figure out my problem.

This is my pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>toreal</groupId>
    <artifactId>toreal</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>TOREAL</name>
    <description>Tableau Optimierung for RElational ALgebra</description>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <antlr4.visitor>true</antlr4.visitor>
        <antlr4.listener>true</antlr4.listener>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.json</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.json</groupId>
            <artifactId>javax.json-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4</artifactId>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                        <webappDirectory>../WebContent</webappDirectory>
                        <!-- webappDirectory is relative to sourceDirectory and basepath var 
                            is not working -->
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.antlr</groupId>
                    <artifactId>antlr4-maven-plugin</artifactId>
                    <version>4.5.3</version>
                    <configuration>
                        <sourceDirectory>${basedir}/src/parser/antlr4</sourceDirectory>
                        <outputDirectory>${project.build.directory}/generated-sources/antlr4</outputDirectory>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>antlr4</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehouse.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.12</version>
                    <executions>
                        <execution>
                            <id>add-source</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>add-source</goal>
                            </goals>
                            <configuration>
                                <sources>
                                    <source>target/generated-sources/antlr4</source>
                                </sources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish</groupId>
                <artifactId>javax.json</artifactId>
                <version>1.0.4</version>
            </dependency>
            <dependency>
                <groupId>javax.json</groupId>
                <artifactId>javax.json-api</artifactId>
                <version>1.0</version>
            </dependency>
            <dependency>
                <groupId>com.googlecode.json-simple</groupId>
                <artifactId>json-simple</artifactId>
                <version>1.1.1</version>
            </dependency>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.7</version>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
            </dependency>
            <dependency>
                <groupId>org.antlr</groupId>
                <artifactId>antlr4</artifactId>
                <version>4.5.3</version>
            </dependency>
            <dependency>
                <groupId>org.antlr</groupId>
                <artifactId>antlr4-runtime</artifactId>
                <version>4.5.3</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <packaging>war</packaging>
</project>

I want to store my .g4 files at /src/main/parser/antlr4/ and the generated Java source files at /target/generated-sources/antlr4. This in an example grammar located at /src/main/parser/antlr4/TestLexer.g4

grammar TestLexer

options{
    language = Java;
    output = AST;
}

H: 'Hello';   
W: 'World';

expression : H W;

When I try to generate the sources within eclipse (with maven build or generate-sources or install) nothing happens. This is an example output of mvn generate-sources:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building TOREAL 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.112 s
[INFO] Finished at: 2016-10-20T18:31:04+02:00
[INFO] Final Memory: 7M/241M
[INFO] ------------------------------------------------------------------------

The /target/generated-sources folder contains an empty annotations folder only but not the Java source files.

Since I am completely new to Maven as well as to Antlr, I appreciate any help to find out what's wrong.

Drudge
  • 528
  • 1
  • 6
  • 20
  • You have all of your config inside ``. Therefore, you also need to declare them inside ``. Refer to http://stackoverflow.com/questions/10483180/maven-what-is-pluginmanagement Also, please don't do that `src`. [Stick to the conventions](https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html), that'll save you some hairs. – Tunaki Oct 20 '16 at 16:35
  • The difference between `` and `` is the same as the difference between `` and ``. Take a look at https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Management – Tunaki Oct 20 '16 at 16:44
  • @Tunaki Thanks I got it now. I have just one question left and don't want to create a new one for this. The files, e.g. `TestLexerLexer.java` are now generated and stored under `target/generated-sources/antlr4`. However, even if this folder is in the build path, I cannot use ´TestLexerLexer.java` in my files stored under `src/*`. Do you have any idea why? – Drudge Oct 20 '16 at 17:41
  • Okay, I found it out on my own. The files definitely need a package. It does not work with the `(default package)` of eclipse. Thanks! – Drudge Oct 20 '16 at 17:51
  • No problem! And as I commented before, you should try to move your source files to `src/main/java`, and the resources to `src/main/resources`. They're a good default that everyone keeps. – Tunaki Oct 20 '16 at 17:53

0 Answers0