Gradle DSL method not found: 'exclude()'

2019-07-30 12:55发布

问题:

I am working in Android Studio and when I added the line in build.gradle file

dependencies {
    compile files('libs/poi-ooxml-schemas-3.12-20150511-a.jar'){
        exclude group: 'stax', module: 'stax-api'
    }
}

I caught the error:

Gradle DSL method not found: 'exclude()'

What is the reason of the error?

回答1:

The way you defined the dependency, you applied the closure to files instead of compile.

files('libs/poi-ooxml-schemas-3.12-20150511-a.jar'){
    exclude group: 'stax', module: 'stax-api'
}

Instead you have to make sure to apply the closure to compile directly.

compile(files('libs/poi-ooxml-schemas-3.12-20150511-a.jar')){
    exclude group: 'stax', module: 'stax-api'
}

But I doubt it's necessary at all. Groups and modules are part of the Maven system and the JAR file itself doesn't have this information to exclude.