Gradle:如何从jar中排除特定的包? [英] Gradle: How to exclude a particular package from a jar?

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

问题描述

我们有一个与某些已删除的要求相关的软件包,但我们不希望删除代码,因为将来可能需要再次删除这些代码。所以在我们现有的ant版本中,我们已经排除了在我们的jar中编译的这个包。这些类不会编译,因为我们也删除了它们的依赖关系,所以它们不能包含在构建中。



我试图模仿在Gradle中的功能如下:

  jar {
sourceSets.main.java.srcDirs = ['src', '../otherprojectdir/src']

include(['com / ourcompany / somepackage / activityadapter / **',
...
'com / ourcompany / someotherpackage / **'])

exclude(['com / ourcompany / someotherpackage / polling / **'])
}

即使使用上面的排除调用(并且我也尝试了它,但没有方括号),gradle仍然试图编译轮询类,这会导致编译失败。如何防止Gradle尝试编译该软件包?

解决方案

如果你有一些你不想做的源代码编译后,您必须为源声明一个过滤器,而不是放入Jar中的类文件。例如:

  sourceSets {
main {
java {
include'com / ourcompany / somepackage / activityadapter / **'
include'com / ourcompany / someotherpackage / **'
exclude'com / ourcompany / someotherpackage / polling / **'
}
}
}


We have a package that is related to some requirements that were removed, but we don't want to necessarily delete the code because there's a possibility it will be needed again in the future. So in our existing ant build, we've just excluded this package from being compiled in our jar. These classes do not compile due to the fact that we've also removed their dependencies, so they can't be included in the build.

I'm attempting to mimic that functionality in Gradle as follows:

jar {
    sourceSets.main.java.srcDirs = ['src', '../otherprojectdir/src']

    include (['com/ourcompany/somepackage/activityadapter/**',
                 ...
        'com/ourcompany/someotherpackage/**'])

    exclude(['com/ourcompany/someotherpackage/polling/**'])
}

Even with the exclude call above (and I've tried it without the square brackets as well), gradle is still attempting to compile the polling classes, which is causing compile failures. How do I prevent Gradle from attempting to compile that package?

解决方案

If you have some sources that you don't want to be compiled, you have to declare a filter for the sources, not for the class files that are put in the Jar. Something like:

sourceSets {
    main {
        java {
            include 'com/ourcompany/somepackage/activityadapter/**'
            include 'com/ourcompany/someotherpackage/**'
            exclude 'com/ourcompany/someotherpackage/polling/**'
        }
    }
}

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

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