Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
630 views
in Technique[技术] by (71.8m points)

java - Gradle: How to exclude a particular package from a 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This solution is valid if you don′t want to compile these packages, but if you want to compile them and exclude from your JAR you could use

// tag::jar[]
jar {
    exclude('mi/package/excluded/**')   
    exclude('mi/package/excluded2/**')  
}
// end::jar[]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...