我是靠谱客的博主 优美羊,这篇文章主要介绍gradle 过滤java,Gradle:如何从jar中排除特定的包?,现在分享给大家,希望可以做个参考。

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 过滤java,Gradle:如何从jar中排除特定的包?的全部内容,更多相关gradle内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(176)

评论列表共有 0 条评论

立即
投稿
返回
顶部