kikibobo wrote:
>
> Has anyone successfully used hibernatetool with gradle?
>
> I sort of got it to work using what seemed like a convoluted path, and
> I'm wondering if there is an easier way.
>
> In the past I have had a db domain project, and its build.xml had
> targets like "drop" that would use the hibernatetool ant task to drop
> the database.
>
> With gradle, I couldn't figure out how to tell hibernatetool to put
> build/classes on its classpath. Things quickly got a bit ugly ... where
> to put hibernate.cfg.xml, for example, so that we don't violate DRY, and
> still have it configurable with username & passwords, etc. It works,
> but it's not exactly better than the old way, which makes me think I
> must be thinking about it wrong, or missing a fundamental concept (it's
> my first day with gradle...).
>
> My work around was to create a peer project that uses my db domain
> project, but I'd really much rather not do that since it's a pretty big
> structural change for a relatively minor little feature.
>
> Any suggestions?
>
> Thanks,
> Eric
>
Ok, this was easier than I was making it out to be. For the benefit of
future searchers (and also to add to the shortage of good ant examples {I
hope}), here's my build.gradle:
(Side note: Any plans to use the more modern ${} notation for filtering,
instead of, or in addition to, the @foo@ notation?)
(Side note #2: the fact that one project depending on another project causes
the other project to do a full build every time I run gradle is a serious
impediment to using gradle...)
dependencies {
compile "javax.persistence:persistence-api:1.0"
compile "org.hibernate:hibernate-core:3.3.1.GA"
compile "org.hibernate:hibernate-annotations:3.4.0.GA"
compile "org.hibernate:hibernate-tools:3.2.0.ga"
compile "mysql:mysql-connector-java:5.0.5"
}
createTask('drop', dependsOn: ['compile'] ) {
ant {
taskdef(name: 'hibernatetool',
classname: 'org.hibernate.tool.ant.HibernateToolTask',
classpath: dependencies.antpath( 'runtime' ))
hibernatetool( destdir : "$buildDir/generated" ) {
annotationconfiguration(
configurationfile:"$classesDir/hibernate.cfg.xml" )
hbm2ddl( export: true, drop: true )
classpath {
pathelement( path: classesDir )
}
}
}
}
createTask( 'generate', dependsOn: ['compile'] ) {
ant {
taskdef(name: 'hibernatetool',
classname: 'org.hibernate.tool.ant.HibernateToolTask',
classpath: dependencies.antpath( 'runtime' ))
mkdir( dir: "$buildDir/generated" )
hibernatetool( destdir : "$buildDir/generated" ) {
annotationconfiguration(
configurationfile:"$classesDir/hibernate.cfg.xml" )
hbm2ddl( export: false, outputfilename: 'schema.sql' )
classpath {
pathelement( path: classesDir )
}
}
}
}
resources.doFirst {
// The parent build file sets up configDir to a per-user/per-machine
directory
// where various specific config (typically properties) files live; we
load them
// here and filter using them, so that hibernate.cfg.xml has the right
database
// credentials.
File databaseProperties = new File( (File) configDir,
'database.properties')
if ( !databaseProperties.exists() ) {
project.logger.warn("Could not find $databaseProperties")
}
Properties props = new Properties()
props.load( new FileInputStream( databaseProperties ) )
resources.filter( props )
}
--
View this message in context:
http://www.nabble.com/hibernatetool-tp21142283p21156599.html
Sent from the gradle-user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email