在Gradle taskdef中使用来自外部Jar的Ant任务

时间:2018-07-12 15:54:56

标签: gradle build.gradle gradle-plugin

我正在尝试使用avro-compiler jar中包含的Ant任务来生成Apache Avro代码。

configurations {
    avroGeneration
}

dependencies {
    // jars are pulled from local repositories (not shown)

    compile 'org.apache.avro:avro:1.5.0-1069339'
    compile 'org.apache.avro:avro-compiler:1.5.0-1069339'
    compile 'org.apache.velocity:velocity:1.6.4'

    compile 'commons-lang:commons-lang:2.6'
    compile 'commons-collections:commons-collections:3.2.2'
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
}

ant.taskdef(
        name: 'protocol',
        classname: 'org.apache.avro.compiler.specific.ProtocolTask',
        classpath: configurations.avroGeneration.asPath)

我尝试按照other posts中的建议将jar添加到类路径,但无济于事。

def antClassLoader = org.apache.tools.ant.Project.class.classLoader
configurations.avroGeneration.each { File f ->
    antClassLoader.addURL(f.toURI().toURL())
}

我得到一个错误。

* What went wrong:
A problem occurred evaluating root project 'trap'.
> taskdef class org.apache.avro.compiler.specific.ProtocolTask cannot be found
   using the classloader AntClassLoader[]

BUILD FAILED in 0s
Unable to load class 'org.apache.avro.compiler.specific.ProtocolTask'.

如何使Ant任务使用特定的jar?

0 个答案:

没有答案