5

I have Findbugs plugin in my main build.gradle file. In order to stop its complain regard some issues I have added annotation.jar and jsr305.jar into my libs folder and I'm using @SuppressFBWarnings wherever needed.

I'm getting following error when I try to build my project.:passenger-

app:dexTaxDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
    at com.android.dx.command.dexer.Main.run(Main.java:277)
    at com.android.dx.command.dexer.Main.main(Main.java:245)
    at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':passenger-app:dexTaxDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 2

Note: I know a solution is activating multidex Building Apps with Over 65K Methods. I also don't believe Progard :(

So, I'm looking for a way to exclude a class from dependent jar file if it's possible. We have something for modules for seems is not possile for jar file.

compile('com.google.android.gms:play-services-analytics:7.3.0') {
        exclude group: 'com.google.android.gms', module: 'play-services-base'
    }

What I have in my main build.gradle file

configure(allprojects) {
    apply plugin: 'findbugs'

    task findbugs(type: FindBugs) {
        ignoreFailures = false
        effort = "max"

        classes = fileTree('build/intermediates/classes/')
        source = fileTree('src/main/java')
        classpath = files()

        excludeFilter = file("$rootProject.rootDir/config/findbugs/exclude.xml")

        reportLevel = "high"
        reports {
            xml.enabled = false
            html.enabled = true
        }
    }
}

and these dependencies in my dependency project

dependencies {
    ....

    // Findbugs libs in order to surpass warnings
    compile files('src/main/libs/annotations.jar')
    compile files('src/main/libs/jsr305.jar')

    ....
}

any suggestion would be appreciated.

Hesam
  • 52,260
  • 74
  • 224
  • 365
  • This should allow you to not include individual packages from your jar.sourceSets { main { java { include 'com/ourcompany/somepackage/activityadapter/**' include 'com/ourcompany/someotherpackage/**' exclude 'com/ourcompany/someotherpackage/polling/**' } } } original SO post here http://stackoverflow.com/questions/27965690/gradle-exclude-or-add-reference-for-jar-file-hard-included-inside-library-class – Doug Ray Oct 28 '15 at 20:30
  • @DougRay Thanks man. Yup, I saw that suggestion and we are using it for some other classes. But that prevents our class get included to jar file. The thing I'm looking for is I have jar and I want to tell buid system that don't include a class. I'm actually not sure my idea works :( – Hesam Oct 28 '15 at 21:02
  • hmmm ok well the next best step would probably be to pick through the gradle documentation. Probablly around the java closures https://docs.gradle.org/current/userguide/java_plugin.html. – Doug Ray Oct 29 '15 at 00:55

1 Answers1

0

Try modifiying the jar closure like this example maybe

project(':api:core') {

        dependencies {
                compile project(':api:schema')
                compile project(':api:util')
        }

        jar {
                baseName = 'core'
                dependsOn classes
                from sourceSets.main.classes
                exclude('net/intellidata/core/**/*Impl*')
        }

        task caaJar(type: Jar) {
                baseName = 'caa' 
                dependsOn classes 
                from sourceSets.main.classes
                include('net/intellidata/core/**/CAA*Impl*')
        }
}
Doug Ray
  • 988
  • 2
  • 9
  • 29
  • not clear how the above helps. OP asked how to exclude dependencies that are brought in by, for example, jsr305.jar – V P Jul 31 '20 at 14:07