logo
Menu

Getting Started with Amazon Q Developer agent for code transformation

This blog will guide you step-by-step to start upgrading your Java 8 or 11 projects to Java 17 code easily using Amazon Q Developer agent for code transformation.

Vinicius Senger
Amazon Employee
Published May 15, 2024
Last Modified May 17, 2024
Upgrade language versions with Amazon Q Developer agent for code transformation
Amazon Q Developer agent for code transformation helps developers save hours (days, and weeks) of time by upgrading Java applications to newer versions easily and quickly. It enables developers to remove much of the undifferentiated work out of tedious tasks of maintaining, upgrading and migrating existing application workloads. It can intelligently upgrade your current language version, starting with Java. Amazon Q Developer agent for code transformation analyzes the entire source code of the application to be transformed, identifies mandatory package dependencies and frameworks and replaces deprecated code with working code. It also incorporates security best practices and executes tests to validate the new upgraded application. This enables you to safely upgrade apps to gain performance improvements while reducing security risks with older, unsupported Java versions. Currently, it can upgrade Java 8 and Java 11 code to Java 17 code.

How to get started?

You can find information on setting up Amazon Q in your IDE, prerequisites, and configuring your project in Q Developer agent for code transformation’s documentation here.

Install the Amazon Q Developer in your IDE

To set up Amazon Q Developer in your integrated development environment (IDE), complete the following steps. After installing the Amazon Q plugin, authenticate through AWS Identity and Access Management or AWS Builder ID. You can use Amazon Q for free, without an AWS account, by authenticating with Builder ID.
To get started, download the Amazon Q plugin for your IDE:
To sign in and authenticate, complete the steps in this section.

Upgrading a Java application from version 8 to 17 - Visual Studio Code

To quickly demonstrate Amazon Q Developer agent for code transformation capabilities, we are using a Spring sample application we developed with the following dependencies / pom.xml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>crud-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>crud-app</name>
<description>CRUD application with MySQL</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.5</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.28.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

1. Make sure your Java 8 / 11 application successfully builds

Before trying Q Developer agent for code transformation, you will need to make sure that you are being able to build, compile and package your project with Maven. We highly recommend you to build and verify the project before starting the transformation process, with maven you can type: mvn clean verify
screenshot of terminal running mvn clean verify command

2. Open the project folder containing your Java 8 application

open project on visual code

3. Open Amazon Q Chat Panel click in the left icon and type "/transform"

Open Amazon Q chat and type /transform

4. Confirm target project and Java versions

Now you have the opportunity to review the source and target Java versions for your project transformation:
confirming the target project and java versions to migrate

5. To start the transformation process, you may need to choose your local JDK 1.8

Visual Studio Code requires you to inform the local path to you JDK 1.8, if you need to discover it open a terminal and type: /usr/libexec/java_home -v 1.8, or you can type which java. Copy and paste in VS Code the path in the output:
provide the JAVA_HOME with the source Java version

6. Amazon Q Developer agent will start the transformation process

Amazon Q Code Transformation will perform the following sequence of tasks:
  1. Build the project locally
  2. Upload the project
  3. Build the project in a secure environment
  4. Analyze the code and create a transformation plan
  5. Update code to new JDK version, dependencies and related code
  6. Build the project with new JDK version
  7. Upgrade deprecated code
  8. Finalize code changes and the transformation summary
  9. Make it available for you to download
To execute it can take up to 30 minutes, you can see this sequence of tasks in this accelerated video:

7. After downloading the project you can review the transformation summary and code changes and accept it

8. Code Transformation Summary By Amazon Q

Amazon Q Developer agent for code transformation will generate a summary.md file with transformation details, in our Spring Java 8 application we had Java code and dependencies updated as follow:

9. Compile and build the transformed project with Java 17

10. Dependencies changes in pom.xml

Spring, jUnit and MySQL dependencies were updated in our pom.xml beside the Java 17 version:
dependencies changes image

Updated pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>crud-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>crud-app</name>
<description>CRUD application with MySQL</description>

<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

Troubleshooting issues with Amazon Q Developer agent for code transformation

The following information can help you troubleshoot common issues with Q Developer agent for code transformation:

Conclusions

We found that upgrading applications using Q Developer agent for code transformation leads to meaningfully large time savings for service teams tasked with upgrading their applications to the latest versions. In this tutorial, you saw an application that was successfully upgraded and built in Java17 after the transformation. For some applications that span multiple modules and with a more complex dependency structure, Q might not be able to complete the build in Java17 after the upgrade and return partially completed code. But, it will still complete major framework upgrades, such as Spring Boot, and replace deprecated APIs. In these scenarios Q will return the partially upgraded code and build log for you to verify and complete the remaining steps to successful build. One situation where builds would fail is if your code uses internal library versions that are incompatible after the upgrade. You can update to the right versions and complete the build from the partially upgraded coded. We see customers benefiting from the transformation output to troubleshoot any missing gaps using the build log summary.
We are continually making improvements to the workflow so we would strongly recommend you test it for your unique workloads and share any feedback for us to feed it back into further improving the product.
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

1 Comment