vscode-gradle/README.md

206 строки
8.4 KiB
Markdown
Исходник Обычный вид История

2020-04-04 16:18:38 +03:00
# VS Code Gradle Tasks
2019-10-31 22:35:30 +03:00
[![Marketplace Version](https://vsmarketplacebadge.apphb.com/version-short/richardwillis.vscode-gradle.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-gradle)
2019-12-21 15:53:35 +03:00
[![Build status](https://img.shields.io/github/workflow/status/badsyntax/vscode-gradle/Build)](https://github.com/badsyntax/vscode-gradle/actions?query=workflow%3ABuild)
2019-12-07 17:45:57 +03:00
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=badsyntax_vscode-gradle&metric=security_rating)](https://sonarcloud.io/dashboard?id=badsyntax_vscode-gradle)
2020-02-16 02:23:05 +03:00
[![Visual Studio Marketplace Installs](https://img.shields.io/visual-studio-marketplace/i/richardwillis.vscode-gradle)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-gradle)
2020-02-16 10:38:20 +03:00
[![GitHub bug issues](https://img.shields.io/github/issues/badsyntax/vscode-gradle/bug?label=bug%20reports)](https://github.com/badsyntax/vscode-gradle/issues?q=is%3Aissue+is%3Aopen+label%3Abug)
2019-10-27 18:54:14 +03:00
2019-12-05 19:26:43 +03:00
Run Gradle tasks in VS Code.
2019-10-20 18:53:00 +03:00
2020-04-27 09:30:22 +03:00
![Gradle Tasks Screencast](images/screencast.gif)
2019-10-20 19:18:21 +03:00
2019-10-23 19:18:24 +03:00
## Features
2019-10-21 20:58:12 +03:00
2020-04-29 10:30:26 +03:00
This extension provides a visual interface for your Gradle build. You can view Gradle projects and run Gradle tasks.
2020-04-23 23:28:46 +03:00
2020-04-24 21:31:10 +03:00
This extension supports whatever Gradle supports and is language/project agnostic, but it can work nicely alongside other extensions like the [Java language support extension](https://github.com/redhat-developer/vscode-java).
2020-04-23 23:28:46 +03:00
👉 [All Features](./FEATURES.md)
2019-10-21 20:58:12 +03:00
2020-01-08 14:54:14 +03:00
## Requirements
2020-02-02 15:13:47 +03:00
- [Java >= 8](https://adoptopenjdk.net/) must be installed
- Local Gradle wrapper executables must exist at the root of the workspace folders
2019-10-20 19:18:21 +03:00
2020-04-25 21:59:35 +03:00
## Settings
2019-10-20 19:18:21 +03:00
This extension contributes the following settings:
2019-12-05 19:26:43 +03:00
- `gradle.autoDetect`: Automatically detect Gradle tasks
- `gradle.enableTasksExplorer`: Enable an explorer view for Gradle tasks
2020-02-19 22:46:25 +03:00
- `gradle.taskPresentationOptions`: Task presentation options, see [tasks output behaviour](https://code.visualstudio.com/docs/editor/tasks#_output-behavior)
- `gradle.focusTaskInExplorer`: Focus the task in the explorer when running a task
2020-04-25 21:59:35 +03:00
- `gradle.javaDebug`: Debug JavaExec tasks (see below for usage)
2019-12-21 15:53:35 +03:00
- `gradle.debug`: Show extra debug info in the output panel
2019-10-21 20:33:13 +03:00
2020-04-10 23:48:31 +03:00
This extension supports the following settings:
- `java.home`: Absolute path to JDK home folder used to launch the gradle daemons (Contributed by [vscode-java](https://github.com/redhat-developer/vscode-java))
- `java.import.gradle.user.home`: Setting for GRADLE_HOME (Contributed by [vscode-java](https://github.com/redhat-developer/vscode-java))
2020-04-29 10:30:26 +03:00
## Supported Environment Variables
Most of the standard Java & Gradle environment variables are supported:
- `JAVE_HOME` (overridden by `java.home`)
- `GRADLE_USER_HOME` (overridden by `java.import.gradle.user.home`)
2020-04-29 10:30:26 +03:00
### Setting Project Environment Variables
2020-04-10 23:48:31 +03:00
2020-04-29 10:30:26 +03:00
You can use an environment manager like [direnv](https://direnv.net/) to set project specific environment variables, or set the variables in the terminal settings within `.vscode/settings.json`, for example:
2020-04-25 21:59:35 +03:00
2020-04-29 10:30:26 +03:00
```json
{
"terminal.integrated.env.osx": {
"GRADLE_USER_HOME": "${workspaceFolder}/.gradle"
}
}
```
2020-04-25 21:59:35 +03:00
Note, the VS Code settings take precedence over the environment variables.
## Debugging JavaExec Tasks
2020-04-25 21:59:35 +03:00
2020-04-27 09:30:22 +03:00
![Debug Screencast](images/debug-screencast.gif)
2020-04-25 21:59:35 +03:00
This extension provides an experimental feature to debug [JavaExec](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html) tasks. Before using this feature you need to install the [Debugger for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug) and [Language Support for Java](https://marketplace.visualstudio.com/items?itemName=redhat.java) extensions.
2020-04-27 09:33:08 +03:00
To enable this feature you need to specify which tasks can be debugged within your project `.vscode/settings.json` file:
2020-04-25 21:59:35 +03:00
```json
"gradle.javaDebug": {
"tasks": [
"run",
"test",
"subproject:customJavaExecTask"
]
}
```
You should now see a `debug` command next to the `run` command in the Gradle Tasks view. The `debug` command will start the Gradle task with [jdwp](https://docs.oracle.com/en/java/javase/11/docs/specs/jpda/conninv.html#oracle-vm-invocation-options) `jvmArgs` and start the vscode Java debugger.
2020-04-29 10:30:26 +03:00
### Debugging Limitations
2020-04-26 00:54:04 +03:00
You'll need to remove any `jdwp` options that might have been set in your task configuration (eg via `jvmArgs`).
## Snippets
This extensions provides snippets for the groovy and kotlin build files:
2019-12-05 19:26:43 +03:00
- `cgt`: Create a new Gradle task
2019-12-11 00:06:10 +03:00
## Troubleshooting
2020-01-01 00:22:45 +03:00
<details><summary>View logs by selecting "Gradle Tasks" in the output panel</summary>
2019-12-11 00:06:10 +03:00
2019-12-14 02:10:42 +03:00
<img src="./images/output.png" width="600" />
2019-12-11 00:06:10 +03:00
2019-12-12 21:11:37 +03:00
</details>
2020-01-01 00:22:45 +03:00
<details><summary>Task output will be shown in the Terminal panel</summary>
2019-12-11 00:06:10 +03:00
2019-12-14 02:10:42 +03:00
<img src="./images/terminal.png" width="600" />
2019-12-11 00:06:10 +03:00
2019-12-12 21:11:37 +03:00
</details>
2020-01-01 00:22:45 +03:00
<details><summary>Set the "gradle.debug" setting to "true" to view debug logs in the output panel</summary>
2019-12-21 15:53:35 +03:00
<img src="./images/debug-output.png" width="600" />
</details>
2020-02-15 20:57:59 +03:00
<details><summary>"No connection to the gradle server. Try restarting the server"</summary>
2020-02-16 10:40:39 +03:00
<img src="./images/no-connection.png" width="500" />
2020-02-15 20:57:59 +03:00
2020-04-23 23:28:46 +03:00
This error means the Gradle Task server has stopped, or there was an error starting it. Click on "Restart Server" to restart it.
2020-02-15 20:57:59 +03:00
2020-02-16 10:38:20 +03:00
If you continue to get this error, view the task error messages by selecting "Gradle Tasks Server" in the Terminal panel.
2020-02-15 20:57:59 +03:00
2020-02-16 10:38:20 +03:00
The task server is started using a [shell script](https://gist.github.com/badsyntax/d71d38b1700325f31c19912ac3428042) generated by [CreateStartScripts](https://docs.gradle.org/current/dsl/org.gradle.jvm.application.tasks.CreateStartScripts.html). The script uses `#!/usr/bin/env sh` and is as portable as the gradle wrapper script. If there are any problems executing the start script then it's likely an issue either with your `$PATH`, or java was not installed.
### PATH problems
The following error demonstrates a typical issue with your `$PATH`:
2020-02-15 21:01:38 +03:00
```shell
env: sh: No such file or directory
The terminal process terminated with exit code: 127
```
Use the following task to debug your shell environment within vscode:
```json
{
"version": "2.0.0",
"tasks": [
{
"label": "Print task shell info",
"type": "shell",
"command": "echo \"Path: $PATH \nShell: $SHELL\"",
"problemMatcher": []
}
]
}
```
2020-02-16 10:38:20 +03:00
#### Fixing your `$PATH`
Check your dotfiles (eg `~/.bashrc`, `~/.bash_profile`, `~/.zshrc`) and fix any broken `PATH` exports, or override the `PATH` env var by setting `terminal.integrated.env` in your vscode settings, for example:
```json
"terminal.integrated.env.osx": {
"PATH": "/put/your:/paths/here",
}
```
### Java path problems
2020-02-16 10:40:39 +03:00
You might see an error like:
2020-02-16 10:38:20 +03:00
```shell
2020-02-16 10:38:20 +03:00
ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
```
2020-02-16 10:43:26 +03:00
The start script [should find](https://gist.github.com/badsyntax/d71d38b1700325f31c19912ac3428042#file-gradle-tasks-server-sh-L85-L105) the path to Java in the usual locations. If you get this error it suggests an issues with your `$PATH` or you simply haven't installed Java. Run the gradle wrapper script (eg `./gradlew tasks`) to debug further.
2020-02-16 10:38:20 +03:00
2020-02-15 20:57:59 +03:00
</details>
<details><summary>Incompatibility with other extensions</summary>
This extension is incompatible with the following extensions:
- [spmeesseman.vscode-taskexplorer](https://marketplace.visualstudio.com/items?itemName=spmeesseman.vscode-taskexplorer)
The reason for the incompatibility is due to the extensions providing the same tasks types (`gradle`) with different task definitions.
</details>
2020-04-18 14:50:35 +03:00
## Support
For general support queries, use the [#gradle-tasks](https://vscode-dev-community.slack.com/archives/C011NUFTHLM) channel in the [slack development community workspace](https://aka.ms/vscode-dev-community), or
2019-12-22 12:09:04 +03:00
- 👉 [Submit a bug report](https://github.com/badsyntax/vscode-gradle/issues/new?assignees=badsyntax&labels=bug&template=bug_report.md&title=)
- 👉 [Submit a feature request](https://github.com/badsyntax/vscode-gradle/issues/new?assignees=badsyntax&labels=enhancement&template=feature_request.md&title=)
2019-12-22 10:20:29 +03:00
2020-04-29 10:30:26 +03:00
## Contributing
Refer to [CONTRIBUTING.md](./CONTRIBUTING.md) for instructions on how to run the project.
- 👉 [Architecture Overview](./ARCHITECTURE.md)
2019-10-20 18:53:00 +03:00
## Credits
- Originally forked from [Cazzar/vscode-gradle](https://github.com/Cazzar/vscode-gradle)
2020-01-01 00:22:45 +03:00
- Inspired by the built-in [npm extension](https://github.com/microsoft/vscode/tree/master/extensions/npm)
2020-04-29 10:30:26 +03:00
- Thanks to all who have submitted bug reports and feedback 👍
## Release Notes
2019-12-12 21:12:46 +03:00
See [CHANGELOG.md](./CHANGELOG.md).
2019-10-20 18:53:00 +03:00
## License
2019-12-12 21:12:46 +03:00
See [LICENSE.md](./LICENSE.md).