Gradle - 从delav jar中提取文件 [英] Gradle - extract file from depended jar
问题描述
我想从取决于jasperreports.jar
的文件中提取文件default.jasperreports.properties,并将其放入带有新名称jasperreports.properties的zip分发版中。
示例gradle构建:
$ b
apply plugin:'java'
任务zip(类型:Zip){'src / dist'
//来自configurations.runtime
from extractFileFromJar(default.jasperreports.properties);
重命名'default.jasperreports.properties','jasperreports.properties'
}
def extractFileFromJar(String fileName){
//配置。 runtime.files.each {file - > println文件} //它不工作
//未完成构建文件的一部分
FileTree tree = zipTree('someFile.zip')
FileTree filtered = tree.matching {
包括文件名
}
}
存储库{
mavenCentral()
}
依赖关系{
runtime'jasperreports:jasperreports:2.0.5'
}
如何获取FileTree在上面的脚本中,我使用
FileTree tree = zipTree('someFile.zip')
但想要使用某些想法(错误,但是可读的)
$ b
FileTree tree = configurations.runtime.filter(jasperreports)。singleFile.zipTree
PS:尝试拨打电话
def extractFileFromJar(String fileName){
configurations.runtime.files.each {file - > println文件} //它不工作
...
但它不起作用除了
您不能更改未处于未解析状态的配置!
这是一个可能的解决方案(有时候代码超过一千字):
apply plugin:java
repositories {
mavenCentral()
}
configurations {
jasper
}
依赖关系{
jasper('jasperreports:jasperreports:2.0.5'){
transitive = false
}
任务zip(类型:Zip){'src / dist'
//注意zipTree调用封装在闭包中,因此配置
//仅在执行时解析$ {$ b $ from({zipTree(configurations.jasper.singleFile)}){
include'default.jasperreports.properties'
rename'defa ult.jasperreports.properties','jasperreports.properties'
}
}
I want to extract file "default.jasperreports.properties" from depended jasperreports.jar and put it in zip distribution with new name "jasperreports.properties"
Sample gradle build:
apply plugin: 'java'
task zip(type: Zip) {
from 'src/dist'
// from configurations.runtime
from extractFileFromJar("default.jasperreports.properties");
rename 'default.jasperreports.properties', 'jasperreports.properties'
}
def extractFileFromJar(String fileName) {
// configurations.runtime.files.each { file -> println file} //it's not work
// not finished part of build file
FileTree tree = zipTree('someFile.zip')
FileTree filtered = tree.matching {
include fileName
}
}
repositories {
mavenCentral()
}
dependencies {
runtime 'jasperreports:jasperreports:2.0.5'
}
How to get FileTree in extractFileFromJar() from dependency jasperreports-2.0.5.jar?
In script above I use
FileTree tree = zipTree('someFile.zip')
but want to use somethink like (wrong, but human readable)
FileTree tree = configurations.runtime.filter("jasperreports").singleFile.zipTree
PS: Try to call
def extractFileFromJar(String fileName) {
configurations.runtime.files.each { file -> println file} //it's not work
...
but it doesn't work with exception
You can't change a configuration which is not in unresolved state!
Here is a possible solution (sometimes code says more than a thousand words):
apply plugin: "java"
repositories {
mavenCentral()
}
configurations {
jasper
}
dependencies {
jasper('jasperreports:jasperreports:2.0.5') {
transitive = false
}
}
task zip(type: Zip) {
from 'src/dist'
// note that zipTree call is wrapped in closure so that configuration
// is only resolved at execution time
from({ zipTree(configurations.jasper.singleFile) }) {
include 'default.jasperreports.properties'
rename 'default.jasperreports.properties', 'jasperreports.properties'
}
}
这篇关于Gradle - 从delav jar中提取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!