Extract specific JARs from dependencies

前端 未结 2 1530

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 ca

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-04 04:17

    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) }
    }
    

提交回复
热议问题