Some dependencies from various libraries have same package name javax.mail. And all the classes inside them are equal with different versions.
I want to be able to choose which class to load at runtime. To be more specific, I have MimeMessage class for email and right now the program is choosing the old version rather than the newer version so this field protected InternetHeaders headers; is not correctly filled and the charset for email and subject is not added so I am unable to send mail with html body.
jar file names :
javax.mail-1.6.2.jar
geronimo-javamail_1.4_spec-1.2.jar
javax.mail-1.5.1.jar
javax.mail-api-1.5.1.jar
all of them have javax.mail.internet.MimeMessage
>Solution :
You may wanna try to
- Exclude the conflicting dependency
dependencies {
compile('org.example:conflict-library:1.0') {
excludes 'geronimo-javamail_1.4_spec'
}
}
- Use dependency management
dependencyManagement {
imports {
mavenBom 'org.example:bom:1.0'
}
dependencies {
dependency 'javax.mail:mail:1.6.2'
}
}
forcing all dependencies on javax.mail:mail to use version 1.6.2
PS: remember to clean and rebuild your project after modifying