Gradle: How to exclude a particular package from a jar?

StormeHawke

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?

Peter Niederwieser

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/**'
        }
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to exclude modules or groups in a jar from Gradle?

From Dev

How to really & fully exclude a package from a jar?

From Dev

How to exclude a package from a jar (with maven)

From Dev

Gradle: How to exclude javax.realtime package from JScience jar dependency (Multiple dex define)

From Dev

Expose particular package from jar

From Dev

Exclude Package From Gradle Dependency

From Dev

In an Android Gradle build, how to exclude dependencies from an included jar file?

From Dev

How to use maven assembly plugin to exclude a package from dependency jar?

From Dev

How do I exclude a package from an imported JAR for a project in Eclipse?

From Dev

Exclude package from external JAR in Android Studio during Gradle build process

From Dev

Gradle - Exclude file from being packaged with jar

From Dev

Exclude .jar from compile in Android Studio with Gradle

From Dev

Gradle - Exclude file from being packaged with jar

From Dev

How to identify a jar file for particular package

From Dev

gradle, how to exclude particular class in a flavor build apk

From Dev

How Do I Exclude a Particular Package Version with SBT

From Dev

Gradle build: Exclude resources files from Spring Boot Jar file

From Dev

OpenEJB: How to exclude jar from module search?

From Dev

Maven - How to exclude dependencies from generated JAR

From Dev

Gradle: exclude package from src/main when building a flavor

From Dev

How to exclude a subdirectory and contents from a nuget package

From Dev

How to exclude package from scoverage in maven

From Dev

How to exclude particular row id from query results?

From Dev

how to exclude particular ajax call from ajaxComplete event listener

From Dev

Gradle JAR - not exporting package

From Dev

How to ignore classes from imported schemas in the generated jar for a particular schema

From Dev

How to exclude resource file from spring boot jar?

From Dev

Maven assembly or shade plugin - How to exclude sources from jar?

From Dev

Exclude BuildConfig.class and R.class from Android library jar in Gradle

Related Related

  1. 1

    How to exclude modules or groups in a jar from Gradle?

  2. 2

    How to really & fully exclude a package from a jar?

  3. 3

    How to exclude a package from a jar (with maven)

  4. 4

    Gradle: How to exclude javax.realtime package from JScience jar dependency (Multiple dex define)

  5. 5

    Expose particular package from jar

  6. 6

    Exclude Package From Gradle Dependency

  7. 7

    In an Android Gradle build, how to exclude dependencies from an included jar file?

  8. 8

    How to use maven assembly plugin to exclude a package from dependency jar?

  9. 9

    How do I exclude a package from an imported JAR for a project in Eclipse?

  10. 10

    Exclude package from external JAR in Android Studio during Gradle build process

  11. 11

    Gradle - Exclude file from being packaged with jar

  12. 12

    Exclude .jar from compile in Android Studio with Gradle

  13. 13

    Gradle - Exclude file from being packaged with jar

  14. 14

    How to identify a jar file for particular package

  15. 15

    gradle, how to exclude particular class in a flavor build apk

  16. 16

    How Do I Exclude a Particular Package Version with SBT

  17. 17

    Gradle build: Exclude resources files from Spring Boot Jar file

  18. 18

    OpenEJB: How to exclude jar from module search?

  19. 19

    Maven - How to exclude dependencies from generated JAR

  20. 20

    Gradle: exclude package from src/main when building a flavor

  21. 21

    How to exclude a subdirectory and contents from a nuget package

  22. 22

    How to exclude package from scoverage in maven

  23. 23

    How to exclude particular row id from query results?

  24. 24

    how to exclude particular ajax call from ajaxComplete event listener

  25. 25

    Gradle JAR - not exporting package

  26. 26

    How to ignore classes from imported schemas in the generated jar for a particular schema

  27. 27

    How to exclude resource file from spring boot jar?

  28. 28

    Maven assembly or shade plugin - How to exclude sources from jar?

  29. 29

    Exclude BuildConfig.class and R.class from Android library jar in Gradle

HotTag

Archive