views:

425

answers:

2

I have maven configured to run gunit (an ANTLR grammar unit testing tool) through the maven-gunit-plugin. gunit, however, has two different modes. The first mode causes gunit to act as an interpreter, reading through the *.gunit (or *.testsuite) file, interpreting it, and displaying the results. It can be configured as such:

  <plugin>
    <groupId>org.antlr</groupId>
    <artifactId>maven-gunit-plugin</artifactId>
    <version>3.1.3</version>
    <executions>
        <execution>
            <id>maven-gunit-plugin</id>
            <phase>test</phase>
            <goals>
                <goal>gunit</goal>
            </goals>
        </execution>
    </executions>
  </plugin>

The second mode causes gunit to generate source code that can be run by JUnit. How can I instruct the maven-gunit-plugin to generate JUnit sources instead of acting as an interpreter?

A few notes:

  • I can change the test phase to "generate-test-sources" to cause the maven plugin to run at the correct time.
  • I couldn't find any useful documentation on the maven-gunit-plugin
  • I've seen people use exec-maven-plugin to run gunit with a specific command line option, but I'm not looking to do that.

EDIT / RESOLUTION:

After reading the various responses, I downloaded the ANTLR source code, which includes the maven-gunit-plugin. The plugin does not support junit generation. It turns out that the codehaus snapshot of the gunit-maven-plugin and the exec plugin are currently the only options.

+3  A: 

I found a discussion through MNG-4039 that is illustrated with a maven-gunit-plugin gunit-maven-plugin sample. I'll let you read the whole article but, according to the author, you should end up with something like this:

<dependencies>
  <dependency>
    <groupId>org.antlr</groupId>
    <artifactId>antlr-runtime</artifactId>
    <version>3.1.1</version>
  </dependency>
  <!-- Here is the 'extra' dep -->
  <dependency>
    <groupId>org.antlr</groupId>
    <artifactId>antlr</artifactId>
    <version>3.1.1</version>
    <!-- we try to use scope to hide it from transitivity -->
    <scope>test</scope> <!-- or perhaps 'provided' (see later discussion) or 'import' (maven >= 2.0.9) -->
  </dependency>
</dependencies>
<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>gunit-maven-plugin</artifactId>
      <version>1.0.0-SNAPSHOT</version>
      <executions>
        <execution>
          <goals>
            <goal>generate</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

I didn't test this configuration myself and can't thus confirm everything is working out of the box. I don't even know if the plugin has been released in a non SNAPSHOT version. The only thing I can confirm is that it seems indeed very hard to find "real" documentation about the maven-gunit-plugin.

Pascal Thivent
gunit-maven-plugin from org.codehaus.mojo isn't the same as maven-gunit-plugin from org.antlr. I'll see, however, if there's a repository/snapshot that works as indicated above.
Kaleb Pederson
@Pascal +1, @Kaleb the plugins are indeed different. The codehaus mojo has been written specifically as a workaround to generate the JUnit test classes. If you are determined to avoid the exec plugin, then this Mojo currently looks to be the best option (assuming it works). Though be warned that the SNAPSHOT suffix means the plugin is volatile and subject to change, you may want to take a local copy and rename/reversion it to avoid picking up breaking changes.
Rich Seller
+1 with Rich's wise words: using a SNAPSHOT version can be fatal to your build stability and I prefer to use "fixed" version for the sake of build reproductability.
Pascal Thivent
+1  A: 

There is sad news here

I found out so far there is no GUnit-functionality (be it JUnit Test-Generation or direct invocation of GUnit) for maven right now. I already mailed with Jim Idle concering the state of GUnit in the
antlr3-maven-plugin and learned that there is a patch to the old version of the maven-plugin waiting in the queue.

I think this workaround that is the only option.

sal
Both referenced posts are older than the original release of the maven-gunit-plugin on May 1, 2009 (see http://www.antlr.org/pipermail/antlr-interest/2009-May/034276.html), so I'm still doubtful that I have a correct answer. Investigating more....
Kaleb Pederson