Gradle - 无法实例化常春藤类

时间:2015-11-06 09:32:11

标签: groovy gradle

我在这里做错了什么?最终目标是从URL下载* .properties。

[我知道不需要解析器,只是试图查看是否存在类名问题。 ]

错误:

    build file '/home/awm/t/build.gradle': 13: unable to resolve class org.apache.ivy.plugins.resolver.URLResolver 
   @ line 13, column 20.
         def resolver = new org.apache.ivy.plugins.resolver.URLResolver()
                        ^

  build file '/home/awm/t/build.gradle': 14: unable to resolve class org.apache.ivy.util.url.ApacheURLLister 
   @ line 14, column 21.
         def urlLister = new org.apache.ivy.util.url.ApacheURLLister()
                         ^

代码:

plugins {
    id "de.undercouch.download" version "2.0.0"
}

import de.undercouch.gradle.tasks.download.Download
import org.apache.ivy.util.url.*

task downloadDirectory {
    def dir = 'http://127.0.0.1:8081/artifactory/gradle-local/props/'
    def resolver = new org.apache.ivy.plugins.resolver.URLResolver()
    def urlLister = new org.apache.ivy.util.url.ApacheURLLister()
    def files = urlLister.listFiles(new URL(dir))
    download {
       src files
       dest "lib"
    }
}

defaultTasks 'downloadDirectory'

1 个答案:

答案 0 :(得分:0)

从Gradle 2.0开始,您需要在Apache Ivy中包含构建脚本依赖项,以使此配方工作。将以下内容放在构建脚本的开头。

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.apache.ivy:ivy:2.3.0'
    }
}

示例:https://github.com/michel-kraemer/gradle-download-task/blob/ddb384d3ee86f038c61ec4e77f21b814b1557a1a/examples/directory.gradle

下载任务的另一个用例:https://www.michel-kraemer.com/recipes-for-gradle-download/