Modernize Java with Cursor and... Note
GitLab

Modernize Java with Cursor and GitLab

Modernizing Java 8 to Java 21 is a complex undertaking involving numerous aspects of software development. AI coding agents like Cursor can efficiently handle focused tasks such as fixing a single failing test. However, they cannot independently determine the overall safety strategy for a multi-step migration. GitLab, through its Duo Agent Platform, orchestrates AI workflows across the software lifecycle to certify these AI-generated changes. The issue hierarchy and GitLab's Model Context Protocol (MCP) server provide essential context to Cursor, enabling it to access GitLab features like CI/CD, security scanning, and impact analysis.The tutorial demonstrates three use cases: fixing a failing end-to-end test, preparing quality gates for modernization, and modernizing HTTP connection handling. The progression prioritizes starting small, adding project context, and then modernizing one boundary at a time, ensuring safety through rigorous review and testing processes. The first use case involves fixing a bug where the Java HTTP metrics collector incorrectly treated all 2xx responses as successful, even when a 503 error was expected. Cursor identified the root cause, fixed the issue, and the resulting merge request was reviewed and merged, establishing a behavioral baseline.The second use case focuses on preparing for the Java 8 to 21 modernization by establishing robust quality gates. This involves configuring GitLab MCP in Cursor to bring project context into the IDE, allowing Cursor to access planning details, discussions, and dependencies. The initial step ensures CI/CD pipelines can test both Java 8 and Java 21 in parallel, with increasing test coverage. Cursor then implements these changes, and the merge request triggers CI/CD pipelines and code review, with any feedback addressed through GitLab's Developer Flow.The final use case involves modernizing the HTTP connection handling by replacing the legacy HttpURLConnection API with Java 21's java.net.http.HttpClient. This is treated as a bounded work item to isolate behavior changes. Cursor implements the replacement, leveraging the GitLab MCP server for context, and the changes are verified locally using a Docker Compose setup. This approach ensures that each modernization step remains manageable, reviewable, and reversible, maintaining a high standard of safety throughout the migration process.