英文:
grails 2 different dependencies with same package names
问题
一些来自不同库的依赖项具有相同的包名称 javax.mail
。并且它们内部的所有类都具有不同版本但相同的类名。
我希望能够在运行时选择要加载的类。更具体地说,我有一个用于电子邮件的 MimeMessage
类,但目前程序选择旧版本而不是新版本,因此这个字段 protected InternetHeaders headers;
没有正确填充,电子邮件和主题的字符集没有添加,因此我无法发送包含 HTML 正文的邮件。
jar 文件名称:
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
它们都包含 javax.mail.internet.MimeMessage
。
英文:
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
答案1
得分: 1
你可以尝试以下操作:
- 排除冲突的依赖项
dependencies {
compile('org.example:conflict-library:1.0') {
excludes 'geronimo-javamail_1.4_spec'
}
}
- 使用依赖管理
dependencyManagement {
imports {
mavenBom 'org.example:bom:1.0'
}
dependencies {
dependency 'javax.mail:mail:1.6.2'
}
}
强制所有依赖于 javax.mail:mail 的依赖项使用版本 1.6.2
PS:在修改后记得清理和重新构建你的项目。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论