如何从 gradle 中的 jar 中排除特定类

Ach*_*ius 5 dependencies gradle spring-boot

我想从 gradle 依赖项中的 jar 中排除特定类

dependencies {
    compile("com.example:myapp") {
        exclude("org/springframework/**")
    }
}
Run Code Online (Sandbox Code Playgroud)

有什么建议么?我被肮脏的班级困住了。

tom*_*ulo 5

您可以使用该任务解压缩 jar Copy,排除所需的类,然后添加对提取的类的文件依赖项。

例如:

task unzipJar(type: Copy) {
   from zipTree('commons-collections-3.2.jar')
   into ("$buildDir/libs/commons-collection")
   include "**/*.class"
   exclude "**/Unmodifiable.class"
}

dependencies {
   compile files("$buildDir/libs/commons-collection") {
      builtBy "unzipJar"
   }
}
Run Code Online (Sandbox Code Playgroud)