Gradle Transitive dependency exclusion is not working as expected. (How do I get rid of com.google.guava:guava-jdk5:13.0 ?)

前端 未结 5 1056
星月不相逢
星月不相逢 2020-12-30 01:57

here is a snippet of my build.gradle:

compile \'com.google.api-client:google-api-client:1.19.0\'
compile \'com.google.apis:google-api-services-oauth2:v2-rev7         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-30 02:21

    Seems like Gradle works in such a way that every dependency brings all its transitive dependencies. And if you exclude some of them from one dependency they might been brought by the others.

    So if you have

    compile 'com.google.api-client:google-api-client:1.19.0'
    compile 'com.google.apis:google-api-services-oauth2:v2-rev77-1.19.0'
    compile 'com.google.apis:google-api-services-plus:v1-rev155-1.19.0'
    

    in order to exclude com.google.guava:guava-jdk5 from the build process you have to exclude it from each of them:

    compile ('com.google.api-client:google-api-client:1.19.0') {
        exclude group: 'com.google.guava', module: 'guava-jdk5'
    }
    compile ('com.google.apis:google-api-services-oauth2:v2-rev77-1.19.0') {
        exclude group: 'com.google.guava', module: 'guava-jdk5'
    }
    compile ('com.google.apis:google-api-services-plus:v1-rev155-1.19.0') {
        exclude group: 'com.google.guava', module: 'guava-jdk5'
    }
    

    dependencyInsight can help to find out where to put exclude. It shows a list of dependencies that have specific dependency in its transitive dependencies (unfortunately it doesn't show which of them have already excluded it in configuration)


    More simple approach is to exclude a dependency from whole configuration (or from all configurations):

    configurations.all {
        exclude group: 'com.google.guava', module: 'guava-jdk5'
    }
    

    Reference: https://docs.gradle.org/current/userguide/resolution_rules.html#excluding_a_dependency_from_a_configuration_completely

提交回复
热议问题