gUnit - Maven Integration

Directory structure:

  • src
    • main
      • java
      • resources
    • test
      • java
        • org.antlr.gunit.test
      • resources
        • org.antlr.gunit.test
      • gunit
        • org.antlr.gunit.test
          • Test.gunit

The following POM parts will generate a JUnit test java file from your gUnit file and includes it in the surefire test run when running the test goal of maven.

<dependencies>
	<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<version>3.8.1</version>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>org.antlr</groupId>
		<artifactId>antlr</artifactId>
		<version>3.1.3</version>
		<scope>compile</scope>
	</dependency>
	<dependency>
		<groupId>org.antlr</groupId>
		<artifactId>gunit</artifactId>
		<version>3.1.3</version>
		<scope>test</scope>
	</dependency>
</dependencies>
<build>
	<plugins>
		<plugin>
			<groupId>org.codehaus.mojo</groupId>
			<artifactId>exec-maven-plugin</artifactId>
			<version>1.1</version>
			<executions>
				<execution>
					<id>gunit-one</id>
					<phase>generate-test-sources</phase>
					<goals>
						<goal>exec</goal>
					</goals>
					<configuration>
						<classpathScope>test</classpathScope>
						<executable>java</executable>
						<testSourceRoot>src\test\gunit\org\antlr\gunit\test</testSourceRoot>
						<workingDirectory>src\test\gunit\org\antlr\gunit\test</workingDirectory>
						<arguments>
							<argument>-classpath</argument>
							<!-- automatically creates the classpath using all project dependencies,
							 also adding the project build directory -->
							<classpath/>
							<argument>org.antlr.gunit.Interp</argument>
							<argument>-o</argument>
							<argument>Test.gunit</argument>
						</arguments>
					</configuration>
				</execution>
				<execution>
					<id>gunit-two</id>
					<phase>generate-test-sources</phase>
					<goals>
						<goal>exec</goal>
					</goals>
					<configuration>
						<classpathScope>test</classpathScope>
						<executable>java</executable>
						<testSourceRoot>src\test\gunit\org\antlr\gunit\test</testSourceRoot>
						<workingDirectory>src\test\gunit\org\antlr\gunit\test</workingDirectory>
						<arguments>
							<argument>-classpath</argument>
							<!-- automatically creates the classpath using all project dependencies,
							 also adding the project build directory -->
							<classpath/>
							<argument>org.antlr.gunit.Interp</argument>
							<argument>-o</argument>
							<argument>Test2.gunit</argument>
						</arguments>
					</configuration>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>
<repositories>
	<!--
	This is the ANTLR repository.
	-->
	<repository>
		<id>antlr-snapshot</id>
		<name>ANTLR Testing Snapshot Repository</name>
		<url>http://antlr.org/antlr-snapshots</url>
		<snapshots>
			<enabled>true</enabled>
			<updatePolicy>never</updatePolicy>
		</snapshots>
	</repository>
</repositories>