Nowadays, the tools involved in the software development process are becoming increasingly important. This is why choosing the appropriate tools can make the developers’ work easier and enable companies to produce better quality software.
An integrated development environment or IDE is an application that facilitates the development of new applications. They are designed to cover all programming tasks in one place, providing a central interface with all the tools a developer needs, such as a code editor, compiler, debugger or automation tools.
This success is largely due to the following factors:
- Multiplatform (macOS, Linux and Windows)
- Free of charge and open code.
- Customizable by means of extensions.
- Fast and light.
Although the initial purpose of Visual Studio Code was as a code editor, it is the extensions that add support for almost any programming language and transform it into a powerful IDE.
To follow this article, it is necessary to have installed on your machine:
- Java Development Kit (JDK). In this guide we shall use JDK 17.
- Apache Maven, version 3.0 or higher.
- Visual Studio Code
In VSCode we will need to install the following extensions:
- Extension Pack for Java. Package of extensions adding Java and Maven compatibility. Also lets you run tests, debug code and develop with IntelliCode.
- Spring Boot Extension Pack. Compatibility with Spring Boot projects.
- Lombok. Optional. For projects where we use Lombok annotations.
To create the initial structure of the Spring Boot project we will use Spring Initializr, which will generate a Spring base project with all the options we have selected.
We can also use Spring Initializr from VSCode, launching the command palette with
Ctrl+Shift+P and executing the
Spring Initializr command
: Create a Maven Project...
For this guide we will use Maven, Java 17, Spring Boot 2.5.5 and Lombok and Spring Security as dependencies.
We extract the zip file generated with Spring Initializr and open the folder from Visual Studio Code.
Once the project is loaded, we will see that it detects the project as a Spring Boot application.
Before launching the application for the first time, we run the
install command from Maven to download the dependencies. We can do it from the Maven plugin integrated with VSCode (left sidebar) or from the terminal.
- Note: By default, VSCode Maven extension uses the Maven executable (mvnw) included in the project. You can specify the path to your local Maven installation from Settings (maven.executable.path).
Finally, we launch the application from the Spring Boot Dashboard.
- Within the project, we can create a folder called
.vscode, where the specific configuration files for the project are located. In addition, if we use version control such as Git, we can include these files to have a common configuration with the rest of the developers in the team.
These are some of the useful files we can add:
settings.json:VSCode settings applied at project level. For example, we can configure a common code formatter for the whole team.
launch.json:Lets you define the parameters with which the application is launched, such as extra parameters of the JVM or environment variables needed to launch the application.
extensions.json:VSCode extensions recommended for our project. If this file exists, when opening the VSCode project, it will recommend installing them if we do not have them.
This would be the
extensions.json file with the three extensions required for this guide:
- Although VSCode detects the Java version of the project and the JDK installed on our computer, we can make adjustments and see the JDKs installed using
Control + Shift + Pfrom the option
Java: Configure Java Runtime
- Other useful commands provided by the Java extension:
Java: Update Project:Forces project configuration / classpath updates (e.g. changes of dependencies or Java compilation level)
Java: Clean Java Language Server Workspace:Clears the Java language server workspace.
Java: Import Java Projects into Workspace:Detects and imports all Java projects in the workspace.
Developer: Reload Window:Relaunches the VSCode window.
Launching the project in Debug mode(F5),we can easily debug our code.
From the VSCode sidebar we can open the Tests explorer and launch our unit tests one by one, or all the tests of the project.
As we have seen, Visual Studio Code makes our work much easier when creating and developing our Spring Boot projects. Moreover, with a few hours of use we will notice its lightness and speed compared to other IDEs, saving time in configuration and start-up.