问题
Duplicate class javax.el.ArrayELResolver found in modules jsp-api-2.1-6.1.14.jar (org.mortbay.jetty:jsp-api-2.1:6.1.14) and jsp-api-2.1.jar (javax.servlet.jsp:jsp-api:2.1) Duplicate class javax.el.BeanELResolver found in modules jsp-api-2.1-6.1.14.jar (org.mortbay.jetty:jsp-api-2.1:6.1.14) and jsp-api-2.1.jar (javax.servlet.jsp:jsp-api:2.1) Duplicate class javax.el.BeanELResolver$BeanProperties found in modules jsp-api-2.1-6.1.14.jar (org.mortbay.jetty:jsp-api-2.1:6.1.14) and jsp-api-2.1.jar (javax.servlet.jsp:jsp-api:2.1) Duplicate class javax.el.BeanELResolver$BeanProperty found in modules jsp-api-2.1-6.1.14.jar (org.mortbay.jetty:jsp-api-2.1:6.1.14) and jsp-api-2.1.jar (javax.servlet.jsp:jsp-api:2.1)
build.gradle:
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//The dependencies below are for a library i'm including after which i get the error
compile "org.bouncycastle:bcprov-jdk15on:1.54"
compile "org.apache.pdfbox:pdfbox:[2.0.15,)"
compile "org.mapdb:mapdb:3.0.4"
compile "com.google.guava:guava:19.0"
compile "com.carrotsearch:java-sizeof:0.0.5"
compile "org.apache.hadoop:hadoop-common:2.7.1"
compile "com.amazonaws:aws-java-sdk:1.11.19"
compile "org.apache.hadoop:hadoop-core:1.2.1"
compile "org.apache.lucene:lucene-analyzers-common:6.1.0"
compile "org.apache.poi:poi-scratchpad:3.15-beta1"
compile "org.apache.poi:poi:3.15-beta1"
compile "org.apache.poi:poi-ooxml:3.15-beta1"
I've read on other threads on stack overflow about using the exclude:group in your build.gradle it's just that i seem to be doing something wrong. Can someone please tell me (i) how to add the exlude statement to the fix the error above instead of giving some generic example (ii) how would i manually remove the modules causing the duplication? (i've tried by removing them from the gradle cache folder even deleted the .gradle folder but it keeps rebuilding it). Any suggestion would be appreciated
回答1:
Firstly compile should be replaced with implementation as it is deprecated. (i) this link provides a good explanation: https://discuss.gradle.org/t/how-to-exclude-transitive-dependency/2119/2 (ii) I searched a lot to find a workable way to go about doing this and most of the suggested methods failed. What actually worked was the following example: Note: duplicate definition of program class Problem: hadoop-common and hadoop-core shared numerous common classes that were causing conflict Solution: I managed to solve it by manually removing the duplicate .class files in the jar file. (i.e. (i) changing the extension from jar to zip (ii) extract it (iii) remove the .class files or the entire folder if it contains all the duplicate files (iv) change the extension from zip back to jar Note do not extract the jar files with Winrar and try to zip them back, for some odd reason that doesn't work. I had to navigate to the Gradle cache: C->Users-> Username -> .gradle -> caches -> modules-2 -> files-2 -> org.apache.hadoop -> find either hadoop-common or hadoop-core and apply the above to delete the folders with duplicate classes
来源:https://stackoverflow.com/questions/58946207/duplicates-class-found-in-modules