How Amazon Q Developer transforms code for Java language upgrades - Amazon Q Developer

How Amazon Q Developer transforms code for Java language upgrades

To transform your code, the Amazon Q Developer Agent for code transformation generates a transformation plan that it uses to upgrade the code language version of your project. After transforming your code, it provides a transformation summary and a file diff for you to review changes before accepting them. The following sections provide more details on how Amazon Q performs the transformation.

Building your code and creating a transformation plan

To begin transforming your code, Amazon Q builds your project locally and generates a build artifact that contains your source code, project dependencies, and build logs.

After generating the build artifact, Amazon Q builds your code in a secure build environment and creates a transformation plan, which is customized to the project or module you’re upgrading. The transformation plan outlines the specific changes Amazon Q will attempt to make, including new dependency versions, major code changes, and suggested replacements for deprecated code. These changes are based on the preliminary build of your code, and might change during the transformation.

Before the transformation begins, you have the option to split up the changes Amazon Q proposes into multiple diffs. This allows you to update and test your code with fewer changes at a time, and will require you to accept changes incrementally after the transformation is complete.

Transforming your code

To transform your code, Amazon Q attempts to upgrade your code based on the proposed changes in the transformation plan. As it makes changes, it re-builds and runs existing unit tests in your source code to iteratively fix any encountered errors.

Amazon Q attempts to make the following changes when upgrading your code:

  • Update deprecated code components according to Java 17 recommendations

  • Upgrade popular libraries and frameworks to a version compatible with Java 17. This includes updating the following libraries and frameworks to their latest available major versions:

    • Apache Commons IO

    • Apache HttpClient

    • bc-fips

    • Cucumber-JVM

    • Hibernate

    • jackson-annotations

    • JakartaEE

    • Javax

    • javax.servlet

    • jaxb-api

    • jaxb-impl

    • jaxen

    • jcl-over-slf4j

    • json-simple

    • jsr305

    • junit

    • junit-jupiter-api

    • Log4j

    • Micronaut

    • Mockito

    • mockito-core

    • Okio

    • PowerMockito

    • Quarkus

    • slf4j

    • slf4j-api

    • Spring Boot

    • Spring Framework

    • Spring Security

    • Swagger

    • testng

Reviewing the transformation summary and accepting changes

After the transformation is complete, Amazon Q provides a transformation summary with details about the changes it made, including the status of the final build which indicates whether your entire project was upgraded. You can also view a build log summary to understand any issues that prevented Amazon Q from building your code in the upgraded version.

The transformation summary additionally includes the differences between the changes proposed in the transformation plan and the changes Amazon Q ultimately made to upgrade your code, and any additional changes that weren’t in the original plan.

After you review the transformation summary, you can view the changes Amazon Q is proposing in a file diff view. Any code changes Amazon Q suggests will not affect your current project files until you accept the changes. The transformed code is available up to 24 hours after the transformation completes.

If you chose to have Amazon Q split up the changes into multiple diffs, it will provide one or more diffs with changes, depending on the upgrades required for your application. If applicable to your application, the changes are categorized in the following groups:

  • Minimum compatible library versions to Java 17: Upgrade dependencies, including Springboot, JUnit, and PowerMockito, to the minimum compatible versions in Java 17.

  • Popular enterprise specifications application frameworks: Upgrade popular enterprise and application frameworks like Jakarta EE, Hibernate, and Micronaut 3.

  • HTTP client utilities web frameworks: Upgrade HTTP client libraries, Apache Commons utilities, and Struts frameworks.

  • Minimum compatible library versions to Java 17: Upgrade dependencies, including Springboot, JUnit, and PowerMockito, to the minimum compatible versions in Java 17.

  • Testing tools frameworks: Upgrade testing tools like ArchUnit, Mockito, and TestContainers and build tools like Jenkins and Maven Wrapper.

  • Miscellaneous processing documentation: Multiple types of upgrades, including ORMs, XML processing, and API documentation like Swagger to SpringDoc/OpenAPI.

  • Deprecated APIs, outdated dependencies, and formatting: Replace deprecated APIs, make additional dependency version upgrades, and format code changes

Amazon Q will provide one diff file at a time, and you must accept changes in a diff to review the following diff. If you reject changes in a diff, you won’t be able to review any other diffs. After you accept changes from one diff, you can review the updates to your code and test the changes before continuing to accept subsequent changes.

Note that there may be minor version downgrades across the diffs. For example, you may see a dependency version upgraded to a newer version in the first diff, and in a subsequent diff see an older version of the dependency. This is because Amazon Q might need to adjust versions to accommodate changes made in each diff. After you accept changes from all the diffs, your code will contain the most recent reliable versions.

The title of the diff will indicate whether the proposed changes will result in a full or partial transformation. If the diff indicates the transformation was only partially successful, then it does not include all necessary changes for a complete transformation and a successful code build. To get the most upgraded version of your code, accept all the code diffs, including partially successful ones. Then, you can manually update your code to address the errors Amazon Q wasn’t able to fix.

Completing partially successful transformations

Depending on the complexity and specifics of your codebase, there might be instances where the transformation is partially successful. This means that Amazon Q was able to transform only certain files or areas of code in your project. In this case, you have to manually update the remaining code for your project to be buildable in the updated language version.

To help transform the rest of your code, you can use Amazon Q chat in the IDE. You can ask Amazon Q to review the partially updated files and provide new code to address issues, such as compilation errors. You can also use features like /dev and @workspace to include more of your project as context and get suggestions for multiple files at a time.