ant - 无法在 groovy gradle 中创建 AntBuilder 对象

标签 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.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
}

构建.gradle

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")
}

谢谢彼得

关于ant - 无法在 groovy gradle 中创建 AntBuilder 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26225767/

相关文章:

java - 使用 Ant 在远程服务器上执行 java 主类

java - 如何在连接速度低的两台计算机之间使用 Ant 复制文件?

grails - 如何使用 GoogleServiceAuthentication 类将文件上传到 grails 中的谷歌存储?

java - 如何为交互式 session 创建有状态的 Groovy 绑定(bind)

grails - groovy中的Web爬虫和Grails每天都要爬网

java - 使用 ant/ivy 从 nexus 检索依赖项之间的 http 身份验证?

java - Eclipse/Ant 在 1.9 版本中制作一个 jar,即使一切似乎都为 1.8 设置

java - Jetty 9 + Spring Boot - 由于缺少 ServletWebServerFactory bean,无法启动 ServletWebServerApplicationContext

linux - Gradle Copy Task 导致文件权限问题

gradle - 如何为每个项目发布多个工件