Gradle将多个依赖项提取到不同的目录 [英] Gradle extract multiple dependencies each to a different directory

查看:530
本文介绍了Gradle将多个依赖项提取到不同的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将多个依赖关系提取到不同的目录中。

 配置{
cppDependencies
}

依赖关系{
cppDependencies'com.group:artifact1:1.0
cppDependencies'com.group:artifact2:1.0
}

任务extractDeps(类型:Copy){
从{
configurations.cppDependencies.collect {
zipTree(it)
}
}
转换为新文件(buildDir,DEP_DIR)
$ b

很明显,这只是提取了 artifact1 artifact2 目录下的 DEP_DIR 目录下。但是我实际上想要实现的是分别在 DEP_DIR / artifact1 DEP_DIR / artifact2 下提取它们。



我尝试将放入 zipTree 命令下的新文件(buildDir,DEP_DIR /+ it.artifactId)中,但它会给出错误信息。



这是可能的吗?

解决方案

我找到了一个可行的解决方案。 b

不知道这是否是最好的方式,但这是我想出来的:

 任务extractDeps<< {
configurations.cppDependencies.resolvedConfiguration.resolvedArtifacts.each {artifact - >
从project.zipTree(artifact.getFile())
拷贝{
到新文件(project.buildDir,DEP_DIR /+ artifact.name)
}
}
}


I'm trying to extract multiple dependencies into different directories. I tried the following.

configurations {
   cppDependencies
}

dependencies {
   cppDependencies 'com.group:artifact1:1.0"
   cppDependencies 'com.group:artifact2:1.0"
}

task extractDeps(type: Copy) {
    from {
        configurations.cppDependencies.collect {
            zipTree(it)
        }
    }
    into new File(buildDir, "DEP_DIR")
}

Obviously this just extracts artifact1 and artifact2 under the same DEP_DIR directory. But what I would actually want to achieve is extract them under DEP_DIR/artifact1 and DEP_DIR/artifact2 respectively.

I tried to put into new File(buildDir, "DEP_DIR/" + it.artifactId) under the zipTree command but it gives an error.

Is this possible?

解决方案

I found a working solution.

Don't know if it's the best way, but this is what I came up with:

task extractDeps << {
    configurations.cppDependencies.resolvedConfiguration.resolvedArtifacts.each { artifact ->
        copy {
            from project.zipTree(artifact.getFile())
            into new File(project.buildDir, "DEP_DIR/" + artifact.name)
        }
    }
}

这篇关于Gradle将多个依赖项提取到不同的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆