Hibernate3 Maven plugin misconfiguration?
The first time i built my project, i already knew that i will get crazy if it does not stop doing things twice and now the time has come. I have not found a solution yet or maybe i just don't know how to search for this issue.
I have some hbm.xml files which get processed within my build process. First of all you can look at the part of my pom.xml which should do the trick.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>generate-xml-files</id>
<phase>generate-resources</phase>
<goals>
<goal>hbm2cfgxml</goal>
</goals>
</execution>
<execution>
<id>generate-entities</id>
<phase>generate-resources</phase>
<goals>
<goal>hbm2java</goal>
</goals>
</execution>
<execution>
<id>generate-schema</id>
<phase>compile</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
</execution>
</executions>
<configuration>
<components>
<component>
<name>hbm2cfgxml</name>
<implementation>configuration</implementation>
<outputDirectory>target/classes</outputDirectory>
</component>
<component>
<name>hbm2java</name>
<implementation>configuration</implementation>
<outputDirectory>src/main/java</outputDirectory>
</component>
<component>
<name>hbm2ddl</name>
<implementation>configuration</implementation>
<outputDirectory>target/classes</outputDirectory>
</component>
</components>
<componentProperties>
<jdk5>true</jdk5>
<packagename>com.blazebit.web.cms.core.model</packagename>
<propertyfile>src/main/resources/database.properties</propertyfile>
<configurationfile>target/classes/hibernate.cfg.xml</configurationfile>
<!-- Tells the plugin to send the output to a file -->
<outputfilename>schema.sql</outputfilename>
<!-- Pretty Format SQL Code -->
<format>true</format>
<!-- Do not create tables automatically - other plug-ins will handle that -->
<export>false</export>
<!-- Do not print the DDL to the console -->
<console>false</console>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.8</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.1_3</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>com.blazebit</groupId>
<artifactId>HibernateCfgBuilder</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>HibernateCfgBuilder</id>
<phase>generate-sources</phase>
<goals>
<goal>HibernateC开发者_如何学GofgBuilder</goal>
</goals>
</execution>
</executions>
<configuration>
<hbmXmlFilesDir>src/main/resources/com/blazebit/web/cms/core/model/</hbmXmlFilesDir>
<configFile>target/classes/hibernate.cfg.xml</configFile>
<packageName>com.blazebit.web.cms.core.model</packageName>
</configuration>
</plugin>
Now let me explain what this all should do.
- First thing is hbm2cfg i think, it should create a hibernate.cfg.xml
- Second step is my own plugin, which adds the paths to the hbm.xml files into the hibernate.cfg.xml(could not find other solutions for this issue)
- Third step is hbm2java which should generate the java files into my sources directory
- And finally hbm2ddl it should create the schema.sql for that model in the classpath
Sounds pretty simple? It even works, but it seems to do some things twice or even more times and now my build takes about 2 minutes which is annoying me :/ Could anyone give me a tip on what i could change to make this steps work?
I think it calls some goals twice because some of hibernate3-maven-plugin
goals "Invokes the execution of the lifecycle phase generate-resources prior to executing itself" as described in documentation. I also faced with this problem and if it really annoy you, so I suggest to try call them as Ant targets from maven-antrun-plugin (but I don't test this).
精彩评论