首页 > 解决方案 > Gradle 下载并解压多个依赖

问题描述

我有一个通用的 Artifatory 存储库,其中包含一些我需要在 Android Studio 项目中下载和提取的 zip 文件。我是 Gradle 新手,但发现使用 Ivy 存储库对象可能是最好的方法,而不是仅使用调用 curl 的 Gradle 任务下载文件。

我已经设法下载并解压缩了一个 zip 文件,但是一旦我尝试添加另一个依赖项,它就会覆盖我的配置。请参阅下面代码中的依赖项块。

为什么它不添加另一个依赖项,有没有更好的方法来做到这一点?

应用程序:build.gradle:

repositories {
    ivy {
        url property("artifactoryUrl")
        credentials {
            username property("artifactoryUser")
            password property("artifactoryPassword")
        }
        authentication {
            basic(BasicAuthentication)
        }
        patternLayout {
            artifact '/[organisation]/[module]/third-party/[revision](.[ext])'
        }
        metadataSources {
            artifact()
        }
    }
}

configurations {
    thirdPartyDependencies
}

dependencies {
    thirdPartyDependencies "artifactory:test-generic:FreeImage@zip"
    thirdPartyDependencies "artifactory:test-generic:GLEW@zip" // thirdPartyDependencies has been overwritten
}

task CopyThirdPartyDependencies(type: Copy) {

    def thirdPartyDirectory = getProject().getRootDir().toString() + "/third-party/"
    println(configurations.thirdPartyDependencies.resolvedConfiguration.resolvedArtifacts)

    configurations.thirdPartyDependencies.resolvedConfiguration.resolvedArtifacts.each { artifact ->
        copy {
            from zipTree(artifact.getFile())
            into thirdPartyDirectory
        }
    }
}

preBuild.dependsOn(CopyThirdPartyDependencies)

标签: android-studiogradlegroovydependenciesartifactory

解决方案


推荐阅读