Do you want your ad here?

Contact us to get your ad seen by thousands of users every day!

[email protected]

Elevating Java Development in Visual Studio Code: Experience the New Build Server for Gradle

  • October 30, 2023
  • 4824 Unique Views
  • 4 min read
Table of Contents

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.

Why Gradle

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.

Image javaext

Step 2 --  Install the "Gradle for Java" extension.

Gradle extension pack

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

Image buildserver

If you encounter any issues during your trial or have any suggestions, please feel free to let us know by creating a GitHub Issue.

Future Plans

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.

Extension pack for Java

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.

Spring boot extension pack

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

Resources

Here is a list of links that are helpful to learn Java on Visual Studio Code.

VS Code: Getting Better and Better for Java

VS Code is getting better and better for Java.

In the last two months, we have made progresses in all key areas including core language support, testing, debugging, refactoring and project management.

Let’s uncover the new hidden gems!

Cycle of: Flag, investigate, leverage data, collaborate, monitor
Five Ways to Use Gradle Enterprise to Identify and Manage Flaky Tests

Dealing with flaky tests is a significant challenge in software development. These unpredictable and inconsistent tests can pass or fail without any changes in code.

How to Create SBOMs in Java with Maven and Gradle

Java is a compiled language, so you should create an SBOM whenever you build a release version of your application. Find out more here!

How Gradle Works: Startup

This is the first of a series on how Gradle works! For example, how does Gradle start up and how many JVMs are involved in a Gradle build?

How Gradle Works: Inside the Daemon

This is the second article of the series “How Gradle Works”. In this article, we’ll explain what happens inside the Gradle Daemon JVM.

Do you want your ad here?

Contact us to get your ad seen by thousands of users every day!

[email protected]

Comments (0)

Highlight your code snippets using [code lang="language name"] shortcode. Just insert your code between opening and closing tag: [code lang="java"] code [/code]. Or specify another language.

No comments yet. Be the first.

Subscribe to foojay updates:

https://foojay.io/feed/
Copied to the clipboard