How can I force Gradle to set the same version for two dependencies?

前端 未结 8 1659
心在旅途
心在旅途 2020-11-29 18:11

I use the following two dependencies:

compile \'com.google.guava:guava:14.0.1\'
compile \'com.google.guava:guava-gwt:14.0.1\'

Both must be

相关标签:
8条回答
  • 2020-11-29 18:40

    Another option is to use dependency constraint: https://docs.gradle.org/current/userguide/dependency_constraints.html

    dependencies {
        implementation 'org.apache.httpcomponents:httpclient'
        constraints {
            implementation('org.apache.httpcomponents:httpclient:4.5.3') {
                because 'previous versions have a bug impacting this application'
            }
            implementation('commons-codec:commons-codec:1.11') {
                because 'version 1.9 pulled from httpclient has bugs affecting this application'
            }
        }
    }
    
    0 讨论(0)
  • 2020-11-29 18:41

    I had a similar situation where one of the dependencies used spring-web 4.2.4 which was broken. You have to force specific library version you want. As mentioned in another comment, it might cause compatibility issues but sometimes is necessary.

    Least intrusive way of forcing a library version I found was instead of using

    compile "org.springframework:spring-web:4.2.3.RELEASE"
    

    specifying dependency configuration as forced:

    compile("org.springframework:spring-web:4.2.3.RELEASE"){
        force = true
    }
    

    I used it when I needed to downgrade Spring version temporarily (until next release).

    0 讨论(0)
提交回复
热议问题