【问题标题】:Multiple Gradle duplicate classes after excluding module from the dependency从依赖项中排除模块后的多个 Gradle 重复类
【发布时间】:2019-09-25 12:32:09
【问题描述】:

Gradle 文件包含以下依赖项

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

    implementation 'javax.xml.bind:jaxb-api:2.2.12'
    implementation 'javax.xml.stream:stax-api:1.0-2'
    implementation 'com.fasterxml:aalto-xml:1.0.0'

    implementation group: 'xerces', name: 'xercesImpl', version: '2.8.0'

    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation 'pub.devrel:easypermissions:0.3.0'
    implementation('com.google.api-client:google-api-client-android:1.23.0') {
        exclude group: 'org.apache.httpcomponents', module: 'commons-codec'
    }
    implementation('com.google.apis:google-api-services-gmail:v1-rev83-1.23.0') {
        exclude group: 'org.apache.httpcomponents'
    }
    implementation 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
}

在其他几个多类错误中,commons-codec 在依赖树中有以下用法

+--- com.google.api-client:google-api-client-android:1.23.0
|    +--- com.google.api-client:google-api-client:1.23.0
|    |    +--- com.google.oauth-client:google-oauth-client:1.23.0
|    |    |    +--- com.google.http-client:google-http-client:1.23.0
|    |    |    |    +--- com.google.code.findbugs:jsr305:1.3.9
|    |    |    |    \--- org.apache.httpcomponents:httpclient:4.0.1
|    |    |    |         +--- org.apache.httpcomponents:httpcore:4.0.1
|    |    |    |         +--- commons-logging:commons-logging:1.1.1
|    |    |    |         \--- commons-codec:commons-codec:1.3
\--- commons-codec:commons-codec:{strictly 1.3} -> 1.3 (c)

图问题可能与传递依赖有关,但据我通过对依赖树的分析可以理解,只有org.apache.httpcomponents 将其用作库,但由于某种原因我无法理解, Gradle 构建文件中的排除声明未按预期工作。

commons-codec 模块相关的Gradle 构建日志

  Duplicate class org.apache.commons.codec.BinaryDecoder found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.BinaryEncoder found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.Decoder found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.DecoderException found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.Encoder found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.EncoderException found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.StringDecoder found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.StringEncoder found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.StringEncoderComparator found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.binary.Base64 found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.binary.BinaryCodec found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.binary.Hex found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.digest.DigestUtils found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.language.DoubleMetaphone found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.language.DoubleMetaphone$DoubleMetaphoneResult found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.language.Metaphone found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.language.RefinedSoundex found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.language.Soundex found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.language.SoundexUtils found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.net.BCodec found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.net.QCodec found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.net.QuotedPrintableCodec found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.net.RFC1522Codec found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)
  Duplicate class org.apache.commons.codec.net.URLCodec found in modules commons-codec-1.3.jar (commons-codec:commons-codec:1.3) and docx4j-6.1.1-SNAPSHOT-shaded.jar (docx4j-6.1.1-SNAPSHOT-shaded.jar)

请注意,docx4j-6.1.1-SNAPSHOT-shaded.jar 是添加到 libs 文件夹中的 jar。不知道为什么这些 jar 文件没有显示在依赖关系树中。

【问题讨论】:

    标签: android gradle android-gradle-plugin


    【解决方案1】:

    因此,通过排除传递依赖的所有实例,它起作用了

    configurations {
        all*.exclude group: 'commons-codec', module: 'commons-codec'
    }
    

    这种方法有什么缺点吗?通过这样做,google-api-client-android 模块中不包含所有使用commons-codec 方法的方法,这些方法使用docx4j-6.1.1-SNAPSHOT-shaded.jar 依赖项?难道这两个不能使用commons-codec 模块的不同构建版本吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-11
      • 1970-01-01
      • 2019-02-12
      • 2018-04-06
      • 1970-01-01
      • 2021-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多