Elevating Java Development in Visual Studio Code: Experience the new Build Server for Gradle
Introducing Build Server for Gradle
In recent years, Gradle has become one of the most popular Java build tools due to its flexibility in configuring build processes and its powerful extensibility. In Visual Studio Code, users can import Gradle projects into their workspace for development. However, there are some areas where support for Gradle projects is not entirely satisfactory, with two major issues that users have below:
- Compiled files are output to the ‘bin’ directory, which differs from Gradle project’s default output location.
- Support for code generation, such as Annotation Processing, is suboptimal.
To address these issues, Microsoft and Gradle have joined forces to explore a novel approach to Gradle project import and building, based on the Build Server Protocol (BSP).
The Build Server for Gradle, developed in collaboration with Gradle, will delegate build tasks to the Gradle build tool, which will be responsible for compiling and generating code directly. This ensures that the results of building in VS Code will be consistent with the output obtained by running Gradle build commands, fundamentally resolving the two major issues below.
What is Build Server Protocol (BSP)
The Build Server Protocol (BSP) draws inspiration from another protocol, the Language Server Protocol (LSP). The purpose behind LSP’s creation was to establish an abstraction layer between development tools and programming languages. With this abstraction layer in place, different development tools that aim to support a particular programming language do not need to individually implement complex functionalities such as code analysis. Instead, they only need to correctly respond to events defined by LSP. For more information about LSP, you can refer to the official LSP website.
BSP, inspired by LSP, seeks to create a similar abstraction layer between development tools and build tools, providing a unified way of exchanging information. BSP is also a valuable complement to LSP. While LSP focuses on functionalities related to code analysis, such as code completion and navigation, BSP is concerned with code building, running, and testing. Together, they form a closed-loop for code development.
Currently, BSP protocol has found widespread application in the Scala development ecosystem, and readers can explore known projects based on BSP on its official website.
Apart from addressing the issues mentioned at the beginning of this article regarding the current support for Gradle projects in VS Code for Java, one of the reasons for prioritizing the implementation of a Gradle-oriented build service is Gradle’s rich Tooling API. At present, nearly all the requests involved in BSP can be achieved through the Gradle Tooling API.
Details and design considerations regarding the Gradle build service we have implemented will be shared in future articles. Please stay tuned for more updates!
How to Get Started
If you want to explore the new Gradle project development experience based on the Gradle Build Server Protocol (BSP) in VS Code, you can follow these steps:
Step 1 – Install the “Extension Pack for Java” extension.
Step 2 – Install the pre-release version of the “Gradle for Java” extension.
Step 3 – Open your Gradle project in VS Code. If the project has been opened in VS Code before, open the command palette (F1) and execute the command “Java: Clean Java Language Server Workspace > Reload and delete.”
Note: Please note that the Gradle Build Server currently does not support Android projects. After the Gradle Build Server starts, it will output status information in the VS Code Output Channel. If you don’t see any output in the Output Channel after loading the project, please try executing the “Java: Clean Java Language Server Workspace > Reload and delete” command again.
Step 4 – Checking Gradle Build Server Status Output
If you encounter any issues during your trial or have any suggestions, please feel free to let us know by creating a GitHub Issue.
We will continue to maintain and enhance the Build Server for Gradle project in the future. In the coming months, in addition to addressing bugs and improving accuracy and stability, we also plan to delegate the running and testing tasks to Gradle execution. This way, even if users have customized complex build processes for testing or running tasks in Gradle scripts, they can be directly handed over to Gradle without the need for additional configuration in the development tool, ensuring an elegant out-of-the-box experience.
Install Extension Pack for Java
To use all features mentioned above, please download and install Extension Pack for Java on Visual Studio Code.
If you are a Spring developer working on a Spring Boot application, you can also download the Spring Boot Extension Pack for specialized Spring experience.
Feedback and suggestions
As always, your feedback and suggestions are very important to us and will help shape our product in future. There are several ways to give us feedback
- Leave your comment on this blog post
- Open an issue on our GitHub Issues page
- Send an email to: email@example.com
Here is a list of links that are helpful to learn Java on Visual Studio Code.
- Learn more about Java on Visual Studio Code.