【问题标题】:Gradle: Ant task for Hibernate InstrumentTask cannot be foundGradle:找不到 Hibernate InstrumentTask 的 Ant 任务
【发布时间】:2015-12-22 12:37:06
【问题描述】:

我已经 gradle 构建文件:

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 时

  • 出了什么问题: 评估项目“:应用程序”时出现问题。

    taskdef 类 org.hibernate.tool.instrument.javassist.InstrumentTask 找不到 使用类加载器 AntClassLoader[]

所以看起来出于某种原因“AntClassLoader”不使用提供的依赖项作为类路径(参见project.sourceSets.main.compileClasspath.asPath

【问题讨论】:

    标签: hibernate ant gradle


    【解决方案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)
    

    【讨论】:

    • 我可以确认这个答案有效。只需检查您的路径:Gradle 4.5 的 fileset(dir: "${project.buildDir}/classes/java/main")
    【解决方案2】:

    在正确设置类路径之前,您在配置阶段调用了 ant.taskdef。您想将其移至执行阶段。比如:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-19
      • 2020-03-08
      • 1970-01-01
      • 2010-11-17
      • 1970-01-01
      • 2015-03-29
      相关资源
      最近更新 更多