greenmail-mail-test / greenmail

Official master for the Greenmail project
http://greenmail-mail-test.github.io/greenmail/
Apache License 2.0
628 stars 180 forks source link

Depend on angus-mail, not jakarta.mail #553

Open michaelhixson opened 1 year ago

michaelhixson commented 1 year ago

I think GreenMail should add a dependency on org.eclipse.angus:angus-mail and remove its dependency on org.eclipse.angus:jakarta.mail.

When I upgraded GreenMail from 2.0.0-alpha-3 to 2.0.1-alpha-1, I had to exclude the dependency on org.eclipse.angus:jakarta.mail in order to resolve duplicate class errors reported by the Maven Enforcer Plugin. That jakarta.mail artifact bundles the classes from two other artifacts: org.eclipse.angus:angus-mail and jakarta.mail:jakarta.mail-api. If either of those other artifacts show up in your dependency tree, you'll have duplicate classes. In particular, GreenMail also depends on jakarta.mail-api, so you will have duplicate classes if you depend on GreenMail 2.0.1-alpha-1.

The release notes for Angus Mail confirm that my suggested approach is the "preferred" way:

Preferred way of using Angus Mail jar files is to use Jakarta Mail API with Angus Mail runtime:

jar file module name groupId artifactId Description
jakarta.mail-api.jar jakarta.mail jakarta.mail jakarta.mail-api The Jakarta Mail API definitions only, suitable for compiling against
angus-mail.jar org.eclipse.angus.mail org.eclipse.angus angus-mail The Angus Mail runtime jar file, including the SMTP, IMAP, and POP3 protocol providers and java.util.logging handler
gimap.jar org.eclipse.angus.mail.gimap org.eclipse.angus gimap An EXPERIMENTAL Gmail IMAP protocol provider that supports Gmail-specific features
dsn.jar org.eclipse.angus.mail.dsn org.eclipse.angus dsn Support for parsing and creating messages containing Delivery Status Notifications

whereas jakarta.mail can be used if you're trying to limit the number of dependencies for some reason. Personally, I feel like artifacts that bundle other artifacts don't play well with Maven-managed dependencies, and they're meant to be used on projects with more manual dependency management.

marcelmay commented 1 year ago

Angus org.eclipse.angus:angus-mail:2.0.1 also depends on jakarta.mail:jakarta.mail-api .

Jakarta.Mail is the essential interface and should be what you program (compile) against, and Angus is one (of theoretically many) implementation(s) of jakarta.mail , and required at runtime.

So, transitively you always have the dependency on jakarta.mail ?

michaelhixson commented 1 year ago

Angus org.eclipse.angus:angus-mail:2.0.1 also depends on jakarta.mail:jakarta.mail-api .

That's not a problem because it depends on jakarta.mail-api. It doesn't bundle jakarta.mail-api.

Meanwhile, jakarta.mail bundles jakarta.mail-api. By "bundle" I mean that its jar file contains copies of all the classes from jakarta.mail-api.

Jakarta.Mail is the essential interface and should be what you program (compile) against, and Angus is one (of theoretically many) implementation(s) of jakarta.mail , and required at runtime.

jakarta.mail:jakarta.mail-api is the interface. org.eclipse.angus:angus-mail is the implementation. Those are what Greenmail should depend on, as the Angus release notes say. "Most people will only need the main Angus Mail implementation in the angus-mail.jar and jakarta.mail-api.jar files together with the Angus Activation on the module path or on the class path."

org.eclipse.angus:jakarta.mail, which should not be used, is both of those jar files combined into a single jar file. Using it in combination with either of the others causes you to have multiple copies of those classes on your classpath.