[英]Gradle : Exclude certain files from packaging (jar) using annotations
我正在尋找一種解決方案,以排除某些帶有特定注釋的文件,這些文件將打包在jar中(可以編譯,但不能創建jar的一部分)。
我已經嘗試了以下步驟
任何指針都會有所幫助。
我能夠實現很長時間了,但是忘記了我在這里發布的問題。
我以前使用的解決方案實際上非常簡單-使用gradle jar
任務-
jar {
excludes = excludedFiles(sourceSets.main.allSource.files)
baseName = artifactName
version = artifactVersion
}
並定義excludedFiles
函數以在提供的源目錄中查找文件-
def excludedFiles(Collection<File> files) {
List<String> classes = new ArrayList<>()
files.each { file ->
if (file.isDirectory()) {
excludedFiles(Arrays.asList(file.listFiles()))
}
else {
if (file.text.contains("@YourAnnotation") && file.text.contains("import foo.bar.YourAnnotation")) {
classes += getClassName(file.absolutePath)
}
}
}
return classes
}
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.