我有一个复制任务集如下:
task copyToLib( type: Copy ) {
into "$buildDir/myapp/lib"
from configurations.runtime
// We only want jars files to go in lib folder
exclude "*.exe"
exclude "*.bat"
exclude "*.cmd"
exclude "*.dll"
// We exclude some lib
exclude group: "org.slf4j", name: "slf4j-api", version: "1.6.2"
}
我收到以下错误:
Could not find method exclude() for arguments [{group=org.slf4j, name=slf4j-api, version=1.6.2}] on task ':copyToLib' of type org.gradle.api.tasks.Copy
我觉得这只是一个语法问题,任何提示?
答案 0 :(得分:3)
按群组排除:exclude group: org.slf4j
按模块排除:exclude module: slf4j-api
按文件名排除:exclude { it.file.name.contains('slf4j-api') }
排除文件:exclude "slf4j-api.jar"
您可以按组和模块排除,但需要进入配置排除这样。然后它会在复制前限制配置。
task copyToLib( type: Copy ) {
into "$buildDir/myapp/lib"
from configurations.runtime {
exclude group: 'org.slf4j'
}
// We only want jars files to go in lib folder
exclude "*.exe"
exclude "*.bat"
exclude "*.cmd"
exclude "*.dll"
}
请记住确保目录存在$buildDir/myapp/lib
也许不是排除所有其他文件只包括罐子?
答案 1 :(得分:0)
也许写一个方法来帮助你
static String generateExcludeJar(Map<String, String> map) {
"$map.name-${map.version}.jar"
// All jar names are like name-version.jar when downloaded by Gradle.
}
exclude generateExcludeJar(group: "org.slf4j", name: "slf4j-api", version: "1.6.2")