I am trying to use both plugin hibernate3-maven-plugin and sql-maven-plugin. My goals is that I can run "maven generate-sources" and it should do :
1) hibernate3-maven-plugin generate the init.sql
2) sql-maven-plugin execute it (an some other script)
The problem with my configuration is : If I run generate-sources with only hibernate3-maven-plugin it works and generate th init.sql but I try to run both plugin it will run sql-maven-plugin first
and end with an error :
Caused by: org.apache.maven.plugin.MojoExecutionException: /my/path/src/main/resources/sql/init.sql not found.
this is my plugins configuration :
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>3.0</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.13</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>create-script</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<configuration>
<hibernatetool destdir="${project.basedir}/src/main/resources/sql/">
<classpath>
<path location="${project.basedir}/src/main/java" />
</classpath>
<configuration
configurationfile="${project.basedir}/src/main/resources/hibernate/hibernate-mysql.cfg.xml" />
<hbm2ddl create="true" drop="true" export="false"
outputfilename="init.sql" format="true" console="true" />
</hibernatetool>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.13</version>
</dependency>
</dependencies>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost/MYDB</url>
<username>root</username>
<password>root</password>
</configuration>
<executions>
<execution>
<id>init-db</id>
<phase>generate-sources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<autocommit>true</autocommit>
<srcFiles>
<srcFile>src/main/resources/sql/init.sql</srcFile>
<srcFile>src/main/resources/sql/insertMessages.sql</srcFile>
</srcFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
UPDATE
In fact I don't want to run sql during my build. I want just to set up an easy way for other developper to reset their db to the latest DB schema and populate with testData. In the end I should run mvn like this : mvn hibernate3:hbm2ddl sql:execute
to execute both plugin
I tryed to remove the <phase/>
in both executions but there is also an error :
ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (default-cli) on project DideuroDb: There was an error creating the AntRun task. NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (default-cli) on project myProject: There was an error creating the AntRun task.
update 2
Configuration like this works a little better :
it generate the init.sql but doen't execute anything :
[INFO] 0 of 0 SQL statements executed successfully
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
configuration updated :
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>3.0</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.13</version>
</dependency>
</dependencies>
<configuration>
<hibernatetool destdir="${project.basedir}/src/main/resources/sql/">
<classpath>
<path location="${project.basedir}/src/main/java" />
</classpath>
<configuration
configurationfile="${project.basedir}/src/main/resources/hibernate/hibernate-mysql.cfg.xml" />
<hbm2ddl create="true" drop="true" export="false"
outputfilename="init.sql" format="true" console="true" />
</hibernatetool>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.13</version>
</dependency>
</dependencies>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost/MYDB</url>
<username>root</username>
<password>root</password>
</configuration>
<executions>
<execution>
<id>init-db</id>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<autocommit>true</autocommit>
<srcFiles>
<srcFile>src/main/resources/sql/init.sql</srcFile>
<srcFile>src/main/resources/sql/insertMessages.sql</srcFile>
</srcFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>