Gradle Visual Studio Code



  1. Visual Studio Code For Beginners
  2. Visual Studio Code Gradle Debug

Requirements

Java 8 or 11 provided by OpenJDK or Oracle. Eclipse OpenJ9 is notsupported, please make sure the JAVA_HOME environment variablepoints to a valid Java 8 or 11 installation.

The Visual Studio breakpoint will trigger and once the control returns to the Java code, you can continue debugging in Android studio: Now we will add a different flavor to the app. Add the following text to the build.gradle file in your app directory. A brief overview of some of the features of the VS Code Gradle Tasks extension. This demo starts with a cold cache, meaning Gradle will need to download the. 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.

macOS, Linux or Windows. Metals is developed on macOS and every PR istested on Ubuntu+Windows.

Scala 2.13, 2.12 and 2.11. Metals supports these Scala versions 2.13.0, 2.13.1, 2.12.8, 2.12.9, 2.12.10, 2.12.7 and 2.11.12.Note that 2.11.x support is deprecated and it will be removed in future releases.It's recommended to upgrade to Scala 2.12 or Scala 2.13

Installation

Install the Metals extension from theMarketplace.

Make sure to disable the extensionsScala Language ServerandScala (sbt)if they are installed. TheDotty Language Serverdoes not need to be disabled because the Metals and Dotty extensions don'tconflict with each other.

Next, open a directory containing a build.sbt file. The extension activateswhen a *.scala or *.sbt file is opened.

Importing a build

The first time you open Metals in a new workspace it prompts you to import the build.Click 'Import build' to start the installation step.

  • 'Not now' disables this prompt for 2 minutes.
  • 'Don't show again' disables this prompt forever, use rm -rf .metals/ to re-enablethe prompt.
  • Use tail -f .metals/metals.log to watch the build import progress.
  • Behind the scenes, Metals uses Bloop toimport sbt builds, but you don't need Bloop installed on your machine to run this step.

Once the import step completes, compilation starts for your open *.scalafiles.

Once the sources have compiled successfully, you can navigate the codebase withgoto definition.

Custom sbt launcher

By default, Metals runs an embedded sbt-launch.jar launcher that respects .sbtopts and .jvmopts.However, the environment variables SBT_OPTS and JAVA_OPTS are not respected.

Update the 'Sbt Script' setting to use a custom sbt script instead of thedefault Metals launcher if you need further customizations like reading environmentvariables.

Speeding up import

The 'Import build' step can take a long time, especially the first time yourun it in a new build. The exact time depends on the complexity of the build andif library dependencies need to be downloaded. For example, this step can takeeverything from 10 seconds in small cached builds up to 10-15 minutes in largeuncached builds.

Consult the Bloop documentationto learn how to speed up build import.

Importing changes

When you change build.sbt or sources under project/, you will be prompted tore-import the build.

Manually trigger build import

Visual Studio Code For Beginners

To manually trigger a build import, execute the 'Import build' command throughthe command palette (Cmd + Shift + P).

Run doctor

Execute the 'Run Doctor' through the command palette to troubleshoot potentialconfiguration problems in your workspace.

Configure Java version

The VS Code plugin uses by default the JAVA_HOME environment variable (viafind-java-home) to locate thejava executable. Metals only works with Java 8 so this executable cannot pointto another version such as Java 11.

To override the default Java home location, update the 'Java Home' variable toin the settings menu.

If this setting is defined, the VS Code plugin uses the custom path instead ofthe JAVA_HOME environment variable.

Visual Studio Code Gradle Debug

macOS

To globally configure $JAVA_HOME for all GUI applications, seethis Stackoverflow answer.

If you prefer to manually configure Java home through VS Code, run the followingcommand to copy the Java 8 home path.

Visual

Custom artifact repositories (Maven or Ivy resolvers)

Use the 'Custom Repositories' setting for the Metals VS Code extension to tellCoursier to try to download Metalsartifacts from your private artifact repository.

Use .jvmopts to set sbt options(https://www.scala-sbt.org/1.0/docs/Proxy-Repositories.html) forsbt bloopInstall which resolves library dependencies. You can also provide acustom sbt script (see 'Custom sbt launcher').

HTTP proxy

Metals uses Coursier to downloadartifacts from Maven Central. To use Metals behind an HTTP proxy, configure thesystem properties -Dhttps.proxyHost=… -Dhttps.proxyPort=… in one of thefollowing locations:

  • .jvmopts file in the workspace directory.
  • JAVA_OPTS environment variable, make sure to start code from your terminalwhen using this option since environment variables don't always propagatecorrectly when opening VS Code as a GUI application outside a terminal.
  • 'Server Properties' setting for the Metals VS Code extension, which can beconfigured per-workspace or per-user.

Using latest Metals SNAPSHOT

Update the 'Server Version' setting to try out the latest pending Metalsfeatures.

VersionPublished
0.7.7-SNAPSHOT10 Oct 2019 22:08
0.7.7-SNAPSHOT10 Oct 2019 22:08

Run the 'Reload Window' command after updating the setting for the new versionto take effect.

Gitignore .metals/ and .bloop/

The Metals server places logs and other files in the .metals/ directory. TheBloop compile server places logs and compilation artifacts in the .bloopdirectory. It's recommended to ignore these directories from version controlsystems like git.

Show document symbols

Run the 'Explorer: Focus on Outline View' command to open the symbol outline forthe current file in the sidebar.

Run the 'Open Symbol in File' command to search for a symbol in the current filewithout opening the sidebar.

As you type, the symbol outline is also visible at the top of the file.

Enable on type formatting for multiline string formatting

To properly support adding | in multiline strings we are using theonTypeFormatting method. To enable the functionality you need to enableonTypeFormatting inside Visual Studio Code.

This needs to be done in settings by checking Editor: Format On Type:

Enable formatting on paste for multiline strings

Whenever text is paste into a multiline string with | it will be properlyformatted by Metals:

To enable this feature you need to enable formatting on paste in Visual StudioCode by checking Editor: Format On PAste:

Coming from IntelliJ

Install theIntelliJ IDEA Keybindingsextension to use default IntelliJ shortcuts with VS Code.

IntelliJVS Code
Go to classGo to symbol in workspace
Parameter infoTrigger parameter hints
Basic completionTrigger suggest
Type infoShow hover
ExpandFold
Extend SelectionExpand selection