【问题标题】:Using Hibernate tools Ant task from Gradle从 Gradle 使用 Hibernate 工具 Ant 任务
【发布时间】: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 的原因,因为我的用例不需要它。我最终确实得到了这个工作......但它看起来与上面的有点不同,当然。

标签: hibernate gradle


【解决方案1】:

我的猜测是您想使用主要源代码集中的类输出目录:

sourceSets.main.output.classesDir

如果您只使用classesDir,Gradle 将尝试解析AntBuilder 实例上的字段。

【讨论】:

  • 我最终完全删除了classesDir。我什至不确定它为什么在那里,但我不需要它。上面是生成一个 DDL,我是从数据库中生成 Java 源代码。然后,我将生成的源代码复制到另一个项目……事实上,我将它们复制到客户端和服务器项目,并使用生成的对象序列化为 XML 在它们之间编组数据。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-02
  • 1970-01-01
相关资源
最近更新 更多