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.
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.projectOpenBehaviour: Specify the default method of opening newly created project ("Interactive", "Open" or "Add to Workspace")
java.gradle.buildServer.enabled: Whether to use build server to synchronize Gradle project ("on" or "off")
java.gradle.buildServer.openBuildOutput: Controls when the build output should open ("neverOpen", "openOnBuildStart" or "openOnBuildFailure")
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
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:
- Generate your classes by running the relevant Gradle Task
- 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.
π Extension API
Troubleshooting
Support
Data/Telemetry
VS Code collects usage data and sends it to Microsoft to help improve our products and services. Read our privacy statement to learn more. If you donβt wish to send usage data to Microsoft, you can set the telemetry.enableTelemetry setting to false. Learn more in our FAQ.
Contributing
Refer to CONTRIBUTING.md for instructions on how to run the project.
π Architecture Overview
Credits
This project was originally started by @badsyntax and is now currently maintained by Microsoft. Huge thanks to @badsyntax who started it all and made this Gradle extension available.
- Originally forked from Cazzar/vscode-gradle
- Inspired by the built-in npm extension
- Thanks to @hanct for providing feature suggestions and BETA testing
- Thanks to @dcermak for providing inspiration to write some unit tests
- Thanks to all who have submitted bug reports and feedback
Related Extensions
Check out vscode-spotless-gradle which formats your source files using Spotless & Gradle.
Release Notes
See CHANGELOG.md.
License
See LICENSE.md.