tags:

views:

36

answers:

2

I've been a long time user of the Make build system, but I have decided to begin learning the Maven build system. While I've read through most of the online docs, none seem to give me the analogies I'm looking for. I understand the system's lifecycle, but I have not see one reference to compile step dependencies. For example, I want to generate a JFlex grammar as part of the compile lifecycle step. Currently, I see no way of making that step a pre-compile phase step. Documentation seems to be limited on this. In general, the concept of step dependencies seem to be baked into Maven and require a plugin for any alteration. Is this the case? What am I missing, because currently the Maven build system seems very limited in how you can setup compilation steps.

A: 

To be frank I think that your current mindset maps much better to ant than to maven, and I would suggest starting with that.

Thorbjørn Ravn Andersen
Does that mean that Maven is not capable of adding additional build tasks to compile? I guess I could put the build steps in an ant file and have mvn just run that. However, that solution seems a bit ugly.
dcolish
You can do anything in Maven. Will reply more in a new answer..
bwawok
I did not say maven could not do it. I said your mindset is closer to ant (coming from make) than maven.
Thorbjørn Ravn Andersen
+2  A: 

You can do anything in Maven. It generally has a default way to do each thing, and then you can hook in and override if you want to do something special. Sometimes it takes a lot of Stack Overflowing and head scratching to figure it out.

I have never used JFlex, but a quick google turned this up

http://jflex.sourceforge.net/maven-jflex-plugin/usage.html

Whenever possible, find someone who has made a Maven plugin do what you want. Even if it isn't 100% right, it may at least give you an idea on how to make maven do something.

Minimal configuration

This configuration generates java code of a parser for all grammar files (.jflex , *.jlex , *.lex , .flex ) found in src/main/jflex/ and its sub-directories. The name and package of the generated Java source code are the ones defined in the grammar. The generated Java source code is placed in target/generated-source/jflex , in sub-directories following the Java convention on package names. pom.xml

<project>
  <!-- ... -->
  <build>
    <plugins>
      <plugin>
        <groupId>de.jflex</groupId>
        <artifactId>maven-jflex-plugin</artifactId>
        <version>1.4.3</version>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
    <!-- ... -->
  </build>
  <!-- ... -->
</project>

This feels like the maven way to do things. Put your stuff in the right folders (src/main/flex), and this plugin will automatically build it into your project. If you want to do fancier custom stuff, there are some options.. but Maven is all about favoring convention over configuration.

bwawok
Oh nice, it was that execution goal that got it working. I guess I'll need to go back and see exactly what that does. So the hook for plugins is adding an execution and that gets run during the lifecycle?
dcolish
Evenrything in Maven is a plugin, even if you don't see it. For wanting to make a change, the first step is to take one of the built in plugins and change the configuration a little... When the built in plugins don't do something, then you can go poke around with 3rd party plugins. If stll no luck, you can make your own :)
bwawok