如何从gradle的罐子中排除特定的类 [英] How to exclude particular class from a jar in gradle

查看:181
本文介绍了如何从gradle的罐子中排除特定的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 依赖项{compile("com.example:myapp"){exclude("org/springframework/**")}} 

有什么建议吗?我被肮脏的课困住了.

解决方案

您可以使用 Copy 任务解压缩jar,排除所需的类,然后在提取的类上添加文件依赖项./p>

例如:

 任务unzipJar(类型:复制){来自zipTree('commons-collections-3.2.jar')放入("$ buildDir/libs/commons-collection")包括"**/*.class"排除"**/Unmodifiable.class"}依赖项{编译文件("$ buildDir/libs/commons-collection"){由"unzipJar"构建}} 

I want to exclude particular class from a jar in gradle dependency

dependencies {
    compile("com.example:myapp") {
        exclude("org/springframework/**")
    }
}

Any suggestions? I am stuck with the dirty class.

解决方案

You can unzip a jar using the Copy task, exclude the desired class and then add a file dependency on the extracted classes.

For example:

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"
   }
}

这篇关于如何从gradle的罐子中排除特定的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆