As the title suggests, this article briefly summarizes the procedure of "Building and running Java using Gradle with VS Code".
What is Gradle? https://ja.wikipedia.org/wiki/Gradle Gradle is a ** open source build automation system ** based on the Apache Ant and Apache Maven concepts, and is a Groovy-based ** domain-specific language instead of the ** XML format used by Apache Maven to declare project settings ( DSL) is adopted. Gradle uses a Directed Acyclic Graph (DAG) to determine the task launch order. Gradle is designed for multi-project builds, which can be very large, and supports incremental builds that intelligently determine which part of the build tree is up to date. Therefore, there is no need to rerun tasks that rely on the latest incremental build part. Early plugins focused primarily on Java, Groovy, and Scala development and deployment, but the roadmap shows workflows for other languages and projects.
Install the main body of VS Code from the following https://code.visualstudio.com/
Search for "Java Extension Pack" in Preference-> Extensions
and install it
If you install this, all the following plugins will be included
・ Language Support for Java (TM) by Red Hat
・ Debugger for Java
・ Java Test Runner
・ Maven for Java
-Java Dependency Viewer
・ Visual Studio IntelliCode
Install Java and set $ JAVA_HOME as an environment variable https://www.java.com/ja/download/help/download_options.xml Add one of the following depending on the Java version used for the ~ / .bash_profile file
export JAVA_HOME=`/usr/libexec/java_home -v 10` #When you want to use java10
export JAVA_HOME=`/usr/libexec/java_home -v 9` #When you want to use java9
export JAVA_HOME=`/usr/libexec/java_home -v 1.8` #When you want to use java8
Install with the following command
brew install gradle
Create a folder for your Gradle project
mkdir project-name-dir
cd project-name-dir
gradle init --type java-application
Since the skeleton is prepared in the initial creation, execute the following to check the operation
gradle build #Build
gradle run #Run
gradle check #Verification
gradle clean #clean
Add JAVA_HOME to VS Code settings as well
Preference->Settings
Search for "javahome" in, open the configuration file and add as below
"java.home": "<2.One of the paths added to the environment variable in>"
Set tasks when running in VS Code
For the settings, add the following to the file .vscode/task.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "./gradlew build"
},
{
"label": "run",
"type": "shell",
"command": "./gradlew run",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "clean",
"type": "shell",
"command": "./gradlew clean"
},
{
"label": "check",
"type": "shell",
"command": "./gradlew check"
}
]
}
Execute the task
You can execute the task defined in Terminal-> Run Task
Actually, I was planning to make a Java application and write an article, but since it is still being implemented, I tried using Gradle with VS Code for the first time, so I tried to organize the process, but it was relatively easy to introduce. It was. It's also a feature of VS Code, but it's lightweight and very comfortable.
Recommended Posts