How to resolve duplicated gradle Dependency issues

后端 未结 4 1649
情话喂你
情话喂你 2021-02-04 01:33

I have tried to test my code with robolectric. Problem is that it has duplicated References. e.g.

java.lang.RuntimeException: java.lang.RuntimeException: Duplica         


        
相关标签:
4条回答
  • 2021-02-04 01:42

    Finally get the test running. I've excluded all libs with duplicated classes:

    testImplementation ("org.robolectric:robolectric:4.3"){
        exclude group: 'org.apache.maven', module: 'maven-artifact'
        exclude group: 'org.apache.maven', module: 'maven-artifact-manager'
        exclude group: 'org.apache.maven', module: 'maven-model'
        exclude group: 'org.apache.maven', module: 'maven-plugin-registry'
        exclude group: 'org.apache.maven', module: 'maven-profile'
        exclude group: 'org.apache.maven', module: 'maven-project'
        exclude group: 'org.apache.maven', module: 'maven-settings'
        exclude group: 'org.apache.maven', module: 'maven-error-diagnostics'
        exclude group: "org.apache.maven.wagon"
    }
    

    Not all possibilities tested but a simple test worked already.

    0 讨论(0)
  • 2021-02-04 01:48

    The solution for me was to ensure that I was not requiring Robolectric in my androidTestImplementation dependencies.

    Once I fixed that, I did not have any conflicts to fix.

    0 讨论(0)
  • 2021-02-04 02:06

    This probably could be written in more general way:

    testImplementation ("org.robolectric:robolectric:4.3") {
        exclude group "org.apache.maven.wagon"
        exclude group "org.apache.maven"
    }
    

    or even:

    testImplementation ("org.robolectric:robolectric:4.3") {
        exclude group: "org.apache.maven", name: "maven-ant-tasks"
    }
    

    because it is maven-ant-tasks of pluginapi, which pulls in org.apache.maven dependencies.

    0 讨论(0)
  • 2021-02-04 02:07

    I've encountered the same issue and the thing that helped me was that I had defined the Roboelectric dependency twice in Gradle file one with androidTestImplementation and the other with testImplementation so when I removed the first part problem solved!!!

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