从依赖关系中提取特定的JAR [英] Extract specific JARs from dependencies

查看:150
本文介绍了从依赖关系中提取特定的JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对gradle很陌生,但很快学习。我需要从发布任务中的某个新目录中获取一些特定的JAR。依赖关系解决好了,但我无法弄清楚,在发布任务中,如何仅将logback-core-1.0.6.jar和logback-access-1.0.6.jar提取到名为lib / ext的目录中。

I am new to gradle but learning quickly. I need to get some specific JARs from logback into a new directory in my release task. The dependencies are resolving OK, but I can't figure out how, in the release task, to extract just logback-core-1.0.6.jar and logback-access-1.0.6.jar into a directory called 'lib/ext'. Here are the relevant excerpts from my build.gradle.

dependencies {
    ...
    compile 'org.slf4j:slf4j-api:1.6.4'
    compile 'ch.qos.logback:logback-core:1.0.6'
    compile 'ch.qos.logback:logback-classic:1.0.6'
    runtime 'ch.qos.logback:logback-access:1.0.6'
    ...
}
...
task release(type: Tar, dependsOn: war) {
    extension = "tar.gz"
    classifier = project.classifier
    compression = Compression.GZIP

    into('lib') {
        from configurations.release.files
        from configurations.providedCompile.files
    }

    into('lib/ext') {
        // TODO:  Right here I want to extract just logback-core-1.0.6.jar and logback-access-1.0.6.jar
    }
    ...
}

如何遍历依赖关系来定位这些特定文件并将它们放入由in创建的lib / ext目录中to('lib / ext')?

How do I iterated over the dependencies to locate those specific files and drop them in the lib/ext directory created by into('lib/ext')?

推荐答案

配置只是(懒惰)集合。您可以遍历它们,过滤它们等。请注意,您通常只需要在构建的执行阶段中执行此操作,而不是在配置阶段中执行此操作。下面的代码通过使用惰性 FileCollection.filter()方法。另一种方法是将闭包传递给 Tar.from()方法。

Configurations are just (lazy) collections. You can iterate over them, filter them, etc. Note that you typically only want to do this in the execution phase of the build, not in the configuration phase. The code below achieves this by using the lazy FileCollection.filter() method. Another approach would have been to pass a closure to the Tar.from() method.

task release(type: Tar, dependsOn: war) {
    ...
    into('lib/ext') {
        from findJar('logback-core') 
        from findJar('logback-access')
    }
}

def findJar(prefix) { 
    configurations.runtime.filter { it.name.startsWith(prefix) }
}

这篇关于从依赖关系中提取特定的JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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