• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

microsoft/vscode-gradle: Manage Gradle Projects, run Gradle tasks and provide be ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

microsoft/vscode-gradle

开源软件地址(OpenSource Url):

https://github.com/microsoft/vscode-gradle

开源编程语言(OpenSource Language):

TypeScript 57.6%

开源软件介绍(OpenSource Introduction):

Gradle for Java

Visual Studio Marketplace Installs Build & Publish GitHub bug issues

This VS Code extension provides a visual interface for your Gradle build. You can use this interface to view Gradle Tasks and Project dependencies, or run Gradle Tasks as VS Code Task. The extension also offers better Gradle file (e.g. build.gradle) authoring experience including syntax highlighting, error reporting and auto completion. The extension works nicely alongside other Java extensions in the Extension Pack for Java.

Requirements

Project Discovery

This extension supports both root and nested Gradle projects. A Gradle project is identified by having Gradle Wrapper scripts (gradlew or gradlew.bat) or Gradle build files (build.gradle or settings.gradle and their Kotlin versions) at the root of a directory. (Nested Gradle project discovery is not enabled by default, set "gradle.nestedProjects": true to enable it.)

Feature Overview

Once the extension is activated you will see a new Gradle icon in the activity bar. Clicking on this icon will reveal some tree views in the sidebar.

Protip: you can move drag & drop any of these tree views into the main explorer view for easier access. This is especially useful for pinned tasks.

You can also run any Gradle task as a VS Code task. Access the Gradle VS Code tasks by running Run Task from the command palette.

List projects and tasks

A Gradle build can have one or more projects. Projects are listed in a flat list with the root project listed first, and sub-projects listed alphabetically thereafter.

When you expand a project, tasks are listed in a tree, grouped by the task group. You can toggle the display of the tasks by clicking on the Show Flat List/Show Tree button in the tree view header.

Gradle Tasks View
List project dependencies

The project's dependencies are included in the Dependencies item under the project. The dependencies are grouped by Gradle configurations and you can expand each configuration to find the corresponding ones. For omitted dependency (marked with a (*)), you can use the inline button Go to Omitted Dependency to go to the previously listed dependency.

Gradle Dependencies
Run tasks

Tasks can be run via:

  • Gradle Projects or Recent Tasks tree views
  • Run Task command
  • Run a Gradle Build command

A running task will be shown with an animated "spinner" icon in the tree views, along with Cancel Task & Restart Task buttons. The Cancel Task button will gracefully cancel the task. The Restart Task button will first cancel the task, then restart it.

Gradle Tasks Running

A task will be run a vscode terminal where you can view the task output.

Send a SIGINT signal (ctrl/cmd + c) in the terminal to gracefully cancel it.

Gradle Tasks Output

Tasks run via the Run a Gradle Build command are not reflected in any of the tree views. Use this command to specify your own Gradle build arguments, for example to run multiple tasks or to exclude tasks.

Run Gradle Build
Control task terminal behaviour

Use one terminal for each task type (default):

"gradle.reuseTerminals": "task"

Use one terminal for all tasks:

"gradle.reuseTerminals": "all"

Don't re-use terminals for any tasks. A new terminal will be created for each task run:

"gradle.reuseTerminals": "off"
Debug tasks

This extension provides an experimental feature to debug JavaExec and Test tasks. Before using this feature you need to install the Debugger for Java and Language Support for Java extensions.

You might need to specify whether you want to clean output cache before debugging, to ensure Gradle doesn't skip any tasks due to output caching (this is most useful when debugging tests).

Output cache is cleaned by adding a cleanTaskName task (eg cleanTest) to the build.

You should now see a debug command next to the run command in the Gradle Projects view. The debug command will start the Gradle task with jdwp jvmArgs and start the vscode Java debugger.

Debug Screencast

Pin tasks

As there could be many tasks in a Gradle project, it can be useful to pin commonly used tasks. Pinned tasks will be shown under their project item. Pin a task by accessing the task context menu (by right-clicking a task). You can also pin a task with specific arguments.

Pin a Gradle Task

To unpin a task, access the task context menu and select Unpin Task, or unpin all pinned tasks by clicking on the Unpin all Tasks button in the overflow button of tree view header.

Unpin a Gradle Task
List recent tasks

Recently run Gradle tasks are listed in a separate tree view. This can be useful to see a history of tasks and to easily access the associated task terminals.

The number shown next to the task is the amount of times the task has been run. Click on the Show Terminal button next to a task to view the most recent terminal for that task. Click on the Close Terminal/s button to close the terminal/s for that task.

Click on the Clear Recent Tasks button in the tree view header to remove all recent tasks from the list, or click on the Close All Terminals button to close all task terminals.

Recent Tasks
List & kill Gradle daemons

Gradle daemon processes are listed by their process ID in a separate tree view and can have the following states: IDLE, BUSY, STOPPED, STOPPING, CANCELED.

Stop individual daemons by clicking on the Stop Daemon button next to the listed daemon.

Stop all daemons by clicking on the Stop Daemons button in the tree view header.

Recent Tasks

After stopping a daemon, it will remain in the STOPPED state for a while, but the underlying process won't exist. This is the default Gradle behaviour.

Most of the time there should be no reason to stop a daemon. View more info on the Gradle Daemon from the Gradle website.

The extension uses the Gradle wrapper to list daemons, and is quite a slow process. If the daemon view is not useful for you, you can simply collapse the view, or disable it completely.

Syntax highlighting for Gradle files

When opening a Groovy Gradle file, the Gradle language server will start and provide language features for you.

Basically, we offer a basic groovy syntax highlighting in gradle files, as VS Code does by default. After language server started, it will analyze the Gradle file and provide semantic tokens information, providing more precise highlighting results.

Syntax Highlighting
Document outline for Gradle files

The Gradle language server will provide the document outline for the current Gradle file. This view will help you to navigate to any part of this Gradle file easily.

Document Outline
Error reporting for Gradle files

The Gradle language server will use Groovy compile engine to analyze the Gradle build file and report syntax errors if exist. It will also get script classpaths from Gradle Build so that it can report compilation errors. The Gradle default imports are supported.

Error Reporting
Auto completion for Gradle files

The Gradle language server supports basic auto completions for a Gradle file, including

  • Basic Gradle closures (e.g. dependencies {})
  • Gradle closures from plugins (e.g. java {})
  • Available methods in Gradle closures (e.g. mavenCentral() in dependencies {})
  • Available fields in Gradle closures (e.g. sourceCompatibility in java {})
  • Available dependencies in Maven central when declaring a dependency in dependencies closure
  • Basic auto completion for settings.gradle (e.g. include())
Auto Completion We will continue improving the auto completion feature to support more cases in writing Gradle files.
Full features list
  • List Gradle Tasks & Projects
  • Run Gradle tasks as VS Code tasks
  • View Gradle Dependencies
  • Supports massive Gradle projects (eg with 10000+ tasks)
  • Uses the Gradle Tooling API to discover and run Gradle tasks
  • Uses a long running gRPC server which provides good performance
  • Supports Kotlin & Groovy build files
  • Supports multi-project builds
  • Supports multi-root workspaces
  • Supports nested projects (enabled via setting)
  • Show flat or nested tasks in the explorer
  • Gracefully cancel a running task
  • Debug tasks
  • Run/debug a task with arguments (supports both build & task args, eg gradle tasks --all --info)
  • Pin tasks
  • List recent tasks
  • List & stop daemons
  • Reports Gradle dist download progress
  • Supports syntax highlighting for Groovy Gradle files
  • Supports document outline for Groovy Gradle files
  • Supports error reporting for Groovy Gradle files
  • Supports auto completion for Groovy Gradle files

Extension Settings

This extension contributes the following settings:

  • gradle.autoDetect: Automatically detect Gradle tasks ("on" or "off")
  • gradle.focusTaskInExplorer: Focus the task in the explorer when running a task (boolean)
  • gradle.nestedProjects: Process nested projects (boolean or an array of directories)
  • gradle.reuseTerminals: Reuse task terminals ("task" [default], "all", or "off")
  • gradle.javaDebug.cleanOutput: Clean the task output cache before debugging (boolean)
  • gradle.debug: Show extra debug info in the output panel (boolean)
  • gradle.disableConfirmations: Disable the warning confirm messages when performing batch actions (eg clear tasks, stop daemons etc) (boolean)
  • gradle.allowParallelRun: Allow to run tasks in parallel, each running will create a new terminal. This configuration will override gradle.reuseTerminals and always create new task terminals when running or debugging a task.

Gradle & Java Settings

Set Gradle & Java options with standard environment variables or standard Gradle settings (eg via gradle.properties or task configuration).

Example Environment Variables

  • JAVA_HOME
  • GRADLE_USER_HOME

Note, the VS Code settings take precedence over the environment variables.

Use an environment manager like direnv to set project specific environment variables

Compatibility with the Java language support extension

Java-Specific Settings

This extension supports the following settings which are contributed by the Java language support extension:

  • java.home: (deprecated Please use java.jdt.ls.java.home as given below) Absolute path to JDK home folder used to launch the Gradle daemons

  • java.jdt.ls.java.home: Absolute path to JDK home folder as per the latest VS code, used to launch the Gradle daemons

  • java.import.gradle.java.home: Absolute path to JDK home folder used to launch the Gradle daemons (if set, this value takes precedence over java.home)

  • java.import.gradle.user.home: Setting for GRADLE_USER_HOME

  • java.import.gradle.jvmArguments: JVM arguments to pass to Gradle

    Note: There should be a space between two arguments

  • java.import.gradle.wrapper.enabled: Enable/disable the Gradle wrapper

  • java.import.gradle.version: Gradle version, used if the Gradle wrapper is missing or disabled

  • java.import.gradle.home: Use Gradle from the specified local installation directory or GRADLE_HOME if the Gradle wrapper is missing or disabled and no 'java.import.gradle.version' is specified.

Class References

There are cases where Gradle tasks will generate Java classes. To ensure these Java classes are indexed correctly by the Java language server, you need to ensure the paths are added to the .classpath, and this is typically achieved using Gradle sourceSets.

Once you've configured your sourceSets correctly, follow these steps:

  1. Generate your classes by running the relevant Gradle Task
  2. Force the Language Server to index the generated classes by right-clicking on build.gradle and selecting Update project configuration.

At this point the Gradle sourceSet paths will be added to the .classpath and the Language Server will automatically update references when those classes change.

Extension API

This extension provides an API which can be used by 3rd-party vscode extensions.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap