Skip to content

Add missing AddDependency for jakarta.servlet.jsp-api in JSP migration#1032

Merged
steve-aom-elliott merged 5 commits intomainfrom
add-jsp-dependency-migration
Mar 30, 2026
Merged

Add missing AddDependency for jakarta.servlet.jsp-api in JSP migration#1032
steve-aom-elliott merged 5 commits intomainfrom
add-jsp-dependency-migration

Conversation

@steve-aom-elliott
Copy link
Copy Markdown
Contributor

Summary

  • The JavaxJspToJakartaJsp recipe uses ChangeDependency to migrate explicit javax.servlet.jsp-api declarations and ChangePackage to rename imports, but has no AddDependency fallback
  • When the JSP API is only available as a transitive dependency (common in Gradle projects), ChangeDependency does nothing while ChangePackage still renames imports to jakarta.servlet.jsp.*, leaving unresolvable references
  • This adds an AddDependency entry matching the pattern already used by JavaxServletToJakartaServlet and JavaxMailToJakartaMail

Fixes compile errors like:

error: package jakarta.servlet.jsp does not exist
import jakarta.servlet.jsp.PageContext;

Test plan

  • New test: addsJakartaJspApiDependencyIfJavaxJspApiOnlyExistsInTransitive — verifies the dependency is added when JSP types are used but no explicit javax JSP dependency exists
  • New test: switchesJavaxJspApiDependencyToJakartaJspApiDependency — verifies existing explicit dependency migration still works

The JavaxJspToJakartaJsp recipe renames javax.servlet.jsp imports to
jakarta.servlet.jsp via ChangePackage, and uses ChangeDependency to
migrate explicit javax.servlet.jsp-api declarations. However, when the
JSP API is only available as a transitive dependency (common in Gradle
projects), ChangeDependency finds nothing to change while ChangePackage
still renames the imports, leaving unresolvable jakarta.servlet.jsp
references.

This adds an AddDependency entry matching the pattern already used by
JavaxServletToJakartaServlet and JavaxMailToJakartaMail, ensuring the
jakarta.servlet.jsp-api dependency is added when JSP types are used
even if the original dependency was transitive.
- Fix copyright year to 2026
- Simplify test assertions by collapsing redundant checks
- Use testParserClasspath + classpathFromResources instead of
  testRuntimeOnly, consistent with other tests like
  JavaxServletToJakartaServletTest
- Regenerate test type table to include javax.servlet.jsp-api-2.3.3
- Fix onlyIfUsing pattern from javax.servlet.jsp.* to
  javax.servlet.jsp..* to cover nested packages like
  javax.servlet.jsp.tagext
@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Mar 30, 2026
- Add upgradesJakartaJspApiDependencyIfAlreadyExistingAtLowerVersion
  test for the UpgradeDependencyVersion path
- Add noChangeIfAlreadyOnJakartaJspApi test verifying no modifications
  when already on jakarta with target version
- Tighten pom assertions to match groupId+artifactId+version together
  as a contiguous pattern, ensuring version numbers belong to the
  correct artifact
Verifies that AddDependency correctly adds jakarta.servlet.jsp-api
when running against a Gradle project where the javax JSP dependency
is only available transitively, matching the customer's actual
build tool.
The tests verify that AddDependency fires when JSP types are used in
source but no explicit javax.servlet.jsp-api dependency is declared,
not necessarily that the dependency exists transitively. Rename to
'WhenNoExplicitJspDependencyDeclared' which accurately describes the
customer scenario (JSP API provided by container jars in WEB-INF/lib).
@steve-aom-elliott steve-aom-elliott merged commit af026f0 into main Mar 30, 2026
1 check passed
@steve-aom-elliott steve-aom-elliott deleted the add-jsp-dependency-migration branch March 30, 2026 16:31
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request test provided

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants