【发布时间】:2013-10-27 23:47:34
【问题描述】:
我想使用 Hibernate 和 Gradle 从现有数据库生成 POJO。 Gradle 可以轻松调用 Ant 任务,Hibernate 有逆向工程数据库的 ant 任务。
我在网上找到了这个旧的 Gradle 任务定义,并将其修改为最新版本的 Gradle,但它不起作用:
ant {
taskdef(name: 'hibernatetool',
classname: 'org.hibernate.tool.ant.HibernateToolTask',
classpath: configurations.compile.asPath )
mkdir( dir: "$buildDir/generated" )
hibernatetool( destdir : "$buildDir/generated" ) {
annotationconfiguration( configurationfile:"$classesDir/hibernate.cfg.xml" )
hbm2ddl( export: false, outputfilename: 'schema.sql' )
classpath {
pathelement( path: classesDir )
}
}
}
我得到错误:
No such property: classesDir for class: org.gradle.api.internal.project.DefaultAntBuilder
如何修改它以从数据库生成架构文件? (我知道这还不会生成 POJO,但这是第一步!)
我的依赖如下:
dependencies {
compile 'org.hibernate:hibernate-tools:4.0.0-CR1'
testCompile group: 'junit', name: 'junit', version: '4.10'
}
【问题讨论】:
-
嗯...我看到我的问题和示例 gradle 任务没有解决相同的问题。 hibernate hbml2ddl 从实体类创建一个 ddl,而不是从数据库中。
-
这也是我后来从类路径中删除
classesDir的原因,因为我的用例不需要它。我最终确实得到了这个工作......但它看起来与上面的有点不同,当然。