无法在groovy gradle中创建AntBuilder对象

无法在groovy gradle中创建AntBuilder对象,ant,groovy,gradle,Ant,Groovy,Gradle,当尝试在groovy文件中创建AntBuidler对象时,我遇到了以下异常 java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildException at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493) at java.lang.C

当尝试在groovy文件中创建
AntBuidler
对象时,我遇到了以下异常

java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildException
at java.lang.Class.getDeclaredConstructors0(Native Method)
  at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)
  at java.lang.Class.getDeclaredConstructors(Class.java:1901)
  .....
  at at features.step_definitions.RewardEventsGeneration.GetEventXML(RewardEventsGeneration.groovy:40)
在✽.然后应生成updateLoyaltyInfo事件

我已将相关jar添加到我的lib文件夹中,然后将其放在
build.gradle

repositories {
    mavenCentral()
    flatDir {
        dirs 'lib'
    }
}
我的代码如下

def GetEventXML (userId, eventTypeIn)
{
    def Host = "10.77.69.14"
    def UserName = "system"
    def Password = "password"
    def Path = "/temp"

    def eventTypeToLookFor = "eventType=\"$eventTypeIn\""
    def resultAsString = "" as String

    def commandToRun = "grep -lH $userId $Path/*.xml | xargs grep -l '$eventTypeToLookFor' | cut -d: -f1"
    def antEventCheck = new AntBuilder();   ********** Error line ******************


        antEventCheck.sshexec(  trust:'true',
                host:Host,
                username:UserName,
                password:Password,
                command:commandToRun,
                verbose:'true',
                timeout:'10000',
                failonerror:'false',
                outputproperty:'eventCheckResult');

        resultAsString = antEventCheck.properties.eventCheckResult.toString()  

    return resultAsString
}
格雷德尔先生

dependencies {
    ext.groovyVersion = "2.0.4"
    ext.cucumberJvmVersion = "1.1.5"
    ext.httpclientVersion = "4.2.1"

    cucumberRuntime files("${jar.archivePath}")

    compile ('com.jcraft:jsch:0.1.49')   

    compile('com.github.groovy-wslite:groovy-wslite:0.8.0')
    groovy("org.codehaus.groovy:groovy-all:${groovyVersion}")
    compile("org.apache.httpcomponents:httpmime:4.1.2")
    compile("org.codehaus.groovy.modules.http-builder:http-builder:0.5.2") {
        exclude group: "org.codehaus.groovy", module: "groovy"
    }
    compile("net.sf.json-lib:json-lib:2.4:jdk15")
    compile("javax.mail:mail:1.4.5")
    compile("org.apache.httpcomponents:httpclient:${httpclientVersion}")
    compile("org.codehaus.geb:geb-core:0.7.2") {
        exclude group: "org.codehaus.geb", module: "geb-implicit-assertions"
    }

    drivers.each { driver ->
        testCompile "org.seleniumhq.selenium:selenium-$driver-driver:$version.selenium"
    }

    compile("org.seleniumhq.selenium:selenium-support:2.25.0")
    compile("log4j:log4j:1.2.17")

    testCompile("junit:junit:4.10")
    testCompile("info.cukes:cucumber-groovy:${cucumberJvmVersion}")
    testCompile("info.cukes:cucumber-junit:${cucumberJvmVersion}")
}

感谢您的评论

以下作品完美无瑕

正如Peter的回答所述,添加
flatDir
是不够的。还需要向依赖项添加相同的内容

repositories {
    mavenCentral()
    flatDir {
        dirs 'lib'
    }
}


dependencies {
    compile("ant:ant:1.7.0")
}

谢谢Peter

依赖项块中有什么?Ant依赖项在那里声明了吗?@PeterNiederwieser我没有把任何东西放在依赖项下。刚刚添加到
repositories
下的
build.gradle
文件中,正如我在问题中根据
http://stackoverflow.com/questions/20700053/how-to-add-local-jar-file-dependency-to-build-gradle-file 
我可以在这里看到我的项目
lib
下的类文件
ant-1.7.0.jar-->\org\apache\tools\ant\BuildException.class
向问题添加了
dependencies
部分
build.gradle
文件构建脚本缺少ant(或lib dir)的依赖项声明。单独指定
flatDir
存储库并没有任何作用。@PeterNiederwieser我在
依赖项下创建了
compile(“ant:1.7.0”)
条目。因为这是与错误中抱怨类相关的
jar
文件。不过我也犯了同样的错误。还有什么我需要做的吗?