2014-03-27 91 views
0

我已經gradle這個build文件:搖籃:對Hibernate InstrumentTask Ant任務無法找到

task hibernateInstrumentation { 
    ant.taskdef(name: 'hibernateInstrumentation' , 
      classpath: project.sourceSets.main.compileClasspath.asPath, 
      classname: 'org.hibernate.tool.instrument.javassist.InstrumentTask'){ 

    } 
    ant.hibernateInstrumentation(verbose: 'true') { 
     fileset(
      dir: "${project.buildDir}", 
      inculde: 'mypackage/model/*.class' 
     ) 
    } 
} 

compileJava.doLast { 
    hibernateInstrumentation 
} 

dependencies { 
    compile "org.hibernate:hibernate-core:$hibernateVersion", 
    compile 'org.javassist:javassist:3.18.1-GA', 
    // ... 
} 

但是當我開始gradle這個

  • 出了什麼問題:發生評估項目 的問題「 :應用'。使用ClassLoader

    的taskdef類org.hibernate.tool.instrument.javassist.InstrumentTask無法找到 AntClassLoader []

所以看起來像某種原因「AntClassLoader」不使用提供依賴關係類路徑(見 project.sourceSets.main.compileClasspath.asPath

回答

0

類路徑已正確設置之前要調用ant.taskdef在配置階段。您想要將其移至執行階段。例如:

task hibernateInstrumentation << { 
     ant.taskdef ... 
    } 
1

該問題的代碼有錯別字和錯誤的元素嵌套。這個工作對我來說:

task hibernateInstrumentation << { 
    ant.taskdef(name: 'hibernateInstrumentation', 
      classpath: project.sourceSets.main.compileClasspath.asPath, 
      classname: 'org.hibernate.tool.instrument.javassist.InstrumentTask') 

    ant.hibernateInstrumentation(verbose: 'true') { 
     fileset(dir: "${project.buildDir}/classes/main") { 
      include(name: 'mypackage/model/*.class') 
     } 
    } 
} 

compileJava.doLast { 
    hibernateInstrumentation.execute() 
} 

dependencies { 
    def hibernateVersion = '5.0.3.Final' 

    compile "org.hibernate:hibernate-core:$hibernateVersion" 
    compile 'org.javassist:javassist:3.18.1-GA' 
    // ... 
} 

使用環境:

Gradle: 2.9 
Groovy: 2.4.4 
Ant:  Apache Ant(TM) version 1.9.3 compiled on December 23 2013 
JVM:  1.8.0_60 (Oracle Corporation 25.60-b23) 
+0

我可以證實,這個答案的作品。只需檢查你的路徑: fileset(dir:「$ {project.buildDir}/classes/java/main」)爲Gradle 4.5 – kai