Extract specific JARs from dependencies

前端 未结 2 1528

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:34

    It is worth nothing that the accepted answer filters the Configuration as a FileCollection so within the collection you can only access the attributes of a file. If you want to filter on the dependency itself (on group, name, or version) rather than its filename in the cache then you can use something like:

    task copyToLib(type: Copy) {
      from findJarsByGroup(configurations.compile, 'org.apache.avro')
      into "$buildSrc/lib"
    }
    
    def findJarsByGroup(Configuration config, groupName) {
      configurations.compile.files { it.group.equals(groupName) }
    }
    

    files takes a dependencySpecClosure which is just a filter function on a Dependency, see: https://gradle.org/docs/current/javadoc/org/gradle/api/artifacts/Dependency.html

提交回复
热议问题