Skip to content

commons-email not migrated in Jakarta EE10 migration #695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jepsar opened this issue Mar 25, 2025 · 2 comments · Fixed by #697
Closed

commons-email not migrated in Jakarta EE10 migration #695

jepsar opened this issue Mar 25, 2025 · 2 comments · Fixed by #697
Labels
enhancement New feature or request

Comments

@jepsar
Copy link

jepsar commented Mar 25, 2025

I ran

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \
    -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:RELEASE \
    -Drewrite.activeRecipes=org.openrewrite.java.migrate.jakarta.JakartaEE10

and found that Apache commons-email library was not upgraded. This is an issue for example when you are using attachments with a jakarta.activation.DataSource.

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-email</artifactId>
      <version>1.5</version>
    </dependency>

should be replaced with:

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-email2-jakarta</artifactId>
      <version>2.0.0-M1</version>
    </dependency>

This is not a drop-in replacement unfortunately. I had to replace org.apache.commons.mail.EmailException with org.apache.commons.mail2.core.EmailException and
org.apache.commons.mail.HtmlEmail with org.apache.commons.mail2.jakarta.HtmlEmail. Probably there are more replacements needed.

Gemini gave me this list:

You're right to be thorough when migrating from Apache Commons Email 1.x to 2.x, especially the Jakarta EE-compatible version. While the core functionality remains similar, there are package changes and some API adjustments.

Here's a breakdown of the key changes and a guide to updating your code:

  1. Dependency Update

As discussed previously, ensure you've replaced your old commons-email dependency with:
XML

org.apache.commons commons-email2-jakarta 1.1 2. Package Changes

The most significant change is the package namespace. For the Jakarta EE version, all classes are now under org.apache.commons.mail2.jakarta.
3. Key Class Replacements

Here's a list of the most commonly used classes and their updated counterparts:

org.apache.commons.mail.Email -> org.apache.commons.mail2.jakarta.Email
org.apache.commons.mail.SimpleEmail -> org.apache.commons.mail2.jakarta.SimpleEmail
org.apache.commons.mail.MultiPartEmail -> org.apache.commons.mail2.jakarta.MultiPartEmail
org.apache.commons.mail.HtmlEmail -> org.apache.commons.mail2.jakarta.HtmlEmail
org.apache.commons.mail.EmailAttachment -> org.apache.commons.mail2.jakarta.EmailAttachment
org.apache.commons.mail.ImageHtmlEmail -> org.apache.commons.mail2.jakarta.ImageHtmlEmail
org.apache.commons.mail.resolver.DataSourceResolver -> org.apache.commons.mail2.jakarta.resolver.DataSourceResolver
org.apache.commons.mail.resolver.DataSourceUrlResolver -> org.apache.commons.mail2.jakarta.resolver.DataSourceUrlResolver
org.apache.commons.mail.resolver.FileDataSourceResolver -> org.apache.commons.mail2.jakarta.resolver.FileDataSourceResolver
org.apache.commons.mail.resolver.InternetDataSourceResolver -> org.apache.commons.mail2.jakarta.resolver.InternetDataSourceResolver
4. Find and Replace

The most efficient way to update your code is to use your IDE's "Find and Replace in Files" feature.
Search for org.apache.commons.mail. and replace it with org.apache.commons.mail2.jakarta..

And after complaining

You are absolutely correct, and I apologize for that oversight. The package changes in Commons Email 2.x go beyond just the root org.apache.commons.mail to org.apache.commons.mail2.jakarta or org.apache.commons.mail2.core.

You've highlighted a critical point: org.apache.commons.mail.EmailException is indeed moved to org.apache.commons.mail2.core.EmailException.

Revised Find and Replace Strategy

Given the more complex package structure in Commons Email 2.x, a more precise find-and-replace strategy is needed:

Jakarta-Specific Replacements:

Find: org.apache.commons.mail.
Replace: org.apache.commons.mail2.jakarta.
This will handle the core email classes.
Core Exception Replacement:

Find: org.apache.commons.mail.EmailException
Replace: org.apache.commons.mail2.core.EmailException
This will handle the exception class.
Resolver Replacements:

Find: org.apache.commons.mail.resolver.
Replace: org.apache.commons.mail2.jakarta.resolver.
Other Exceptions:

Carefully review any other exceptions that are used. There is a chance that other exceptions were also moved to the core package.

CC @melloware

@jepsar jepsar added the enhancement New feature or request label Mar 25, 2025
@melloware
Copy link
Contributor

From looking at the source code I think it's just a simple package replace. Everything is under .jakarta. In commons email2

melloware added a commit to melloware/rewrite-migrate-java that referenced this issue Mar 26, 2025
@melloware
Copy link
Contributor

PR submitted!

melloware added a commit to melloware/rewrite-migrate-java that referenced this issue Mar 26, 2025
melloware added a commit to melloware/rewrite-migrate-java that referenced this issue Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants