Gradle Visual Studio Code



Although we can use IDE for creating new java projects, if we use a build tool like gradle and create the project from ground up then not only we have more control, we can also change between IDEs as we feel the need.

  1. Run the 'Reload Window' command after updating the setting for the new version to take effect. Gitignore.metals/ and.bloop/. The Metals server places logs and other files in the.metals/ directory. The Bloop compile server places logs and compilation artifacts in the.bloop directory. It's recommended to ignore these directories from version control systems like git.
  2. Gradle Tasks This VS Code extension provides a visual interface for your Gradle build. It supports whatever Gradle supports and is language agnostic, but can work nicely alongside other extensions like the Java language support extension.
  3. First of all - Android Studio and Visual Studio are IDE's. Tools to create code. What you are asking is programming framework. I assume that when you are talking about Android Studio you mean Native Android Development and by Visual Studio you mean Xamarin. If you want to create crossplatform app then Native Android Development is NOT a way to go.

Create new application

Microsoft Visual Studio Enterprise 2015 Version 14.0.24720.00 Update 1 Microsoft.NET Framework Version 4.6.01055 I'm trying to build a cordova project for a device (not an emulator) and get the below output: 1 - Building platform: android 1 Debug 1 - Build configuration options: -debug 1 Executing 'beforecompile' hook for all plugins. 1 ANDROIDHOME=E: Program Files (x86. This extension provides support to run gradle tasks. To configure the usage of the system gradle please add 'gradle.useCommand': 'gradle' into your settings.json.

Gradle Tasks Visual Studio Code

Studio

Create new java-application type Java project using gradle -

Please note: The Build Init plugin is currently incubating. Please be aware that the DSL and other configuration may change in later Gradle versions. To know more about gradle supported java projects read Gradle Build Init plugin documentation.

This command create a gradle.build file with the contents

Gradle tasks

To check all tasks of the project run -

You will see list of tasks available for the project and short description about what the task is about. If you want to run any of the task then just run

where <task name> is the task from the previous command. For example If you run -

then the distribution(compressed executable) file will be found in buld>distributions folder. There is tar and zip archive. You can extract and use either of them.

You can create new custom tasks or add plugin that have prebuilt task that you can use.

Code Coverage metric

Code coverage is one of the most important metric for any project. From Wikipedia -

In computer science, test coverage is a measure used to describe the degree to which the source code of a program is executed when a particular test suite runs. A program with high test coverage, measured as a percentage, has had more of its source code executed during testing which suggests it has a lower chance of containing undetected software bugs compared to a program with low test coverage.

We are going to use JaCoCo1 for test coverage. At first we need to add JaCoCo as dependencies -

Now if we run -

Gradle tasks visual studio codeVisual studio code gradle classpath

we will see that there is two new task available under Verification tasks

now we can create code coverage report by running -

but I want to create code coverage report when I run gradle test command which run all tests for the project. To do so edit your gradle.build file -

Visual Studio Code Gradle Extension

Now run gradle build or gradle test to generate the Code Coverage Report. The Code Coverage Report can be found in build>reports>jacoco>test>html. Open the index.html file here to view the Coverage Report

Please Note: We can use JaCoCo to generate Code Coverage Report for Continuous Code Quality tools like SonarQube2. I will discuss about it in future articles.

Gradle

References:

  1. JaCoCo is a free code coverage library for Java, which has been created by the EclEmma team based on the lessons learned from using and integration existing libraries for many years. ↩

  2. SonarQube - SonarQube is an open source platform for continuous inspection of code quality to perform automatic reviews with static analysis of code to detect bugs, code smells and security vulnerabilities on 20+ Programming languages. SonarQube offers reports on duplicated code, coding standards, unit tests, code coverage, code complexity, comments, bugs, and security vulnerabilities. SonarQube can record metrics history and provides evolution graphs. SonarQube’s greatest asset is that it provides fully automated analysis and integration with Maven, Ant, Gradle, MSBuild and continuous integration tools. SonarQube also integrates with Eclipse, Visual Studio and IntelliJ IDEA development environments through the SonarLint plugins and integrates with external tools like LDAP, Active Directory, GitHub, etc. ↩

Gradle is a build tool that can be used easily with a large number ofprogramming languages including Scala. With it you can easily define your buildsfor Groovy or Kotlin, which enables for a high degree of customization. You canlook up all the possible features on the Gradle website.

Automatic installation

The first time you open Metals in a new Gradle workspace you will beprompted to import the build. Select 'Import Build' to start theautomatic installation. This will create all the needed Bloop configfiles. You should then be able to edit and compile your code utilizingall of the features.

Manual installation

Visual Studio Code Gradle Kotlin

In a highly customized workspaces it might not be possible to use automaticimport. In such cases it's quite simple to add the capability to generate theneeded Bloop config.

First we need to add the Bloop plugin dependency to the project. It should beincluded in the buildscript section:

Secondly, we need to enable the plugin for all the projects we want to include.It's easiest to define it for allprojects:

Now we can run gradle bloopInstall, which will create all of the Bloopconfiguration files.

This will enable us to work with Metals and all features should work.