Search code examples
javamavenhibernate3-maven-plugin

How to make sure Maven plugin is executed before classes are compiled?


I have created a Maven project, which contains Java domain classes that are generated from database tables, using hibernate3-maven-plugin. The same project however also contains Dao classes that make use of these generated domain classes.

When compiling the project using mvn clean compile, the build will fail because the Dao classes won't compile: the domain classes have not been compiled yet. The domain classes won't be generated because the build fails. As if running in a circle. :-)

How can I make sure, the plugin generates the domain classes, before the dao classes are compiled?

Thanks!


Solution

  • You must bind the generation of the domain classes i.e. the execution of the hibernate plugin to a Maven phase that is executed before the compile phase, e.g. generate-sources.

    <build>
    <plugins>
      <plugin>
        <artifactId>hibernate3-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>(goal for generating sources)</goal>
            </goals>
            <phase>generate-sources</phase>
    

    See http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

    When you generate your sources to the target dir, the Maven compiler plugin should pick them up and compile them.