I usually use JavaScript, so please let me know if there are any mistakes. Just in case, I will install the tools etc.!
This time I will use chocolatey. Click here to install chocolatey (https://chocolatey.org/install#install-with-cmdexe)
choco install vscode -y
choco install gradle -y
choco install openjdk -y
First, create an appropriate folder and open it with VS Code.
mkdir sample-project
cd sample-project
code . #Open the current directory with vscode
From here it's OK to do it in the vscode terminal
gradle init
#Option selection
Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4] 2
Select implementation language:
1: C++
2: Groovy
3: Java
4: Kotlin
5: Swift
Enter selection (default: Java) [1..5] 3
Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) [1..2] 1
Select test framework:
1: JUnit 4
2: TestNG
3: Spock
4: JUnit Jupiter
Enter selection (default: JUnit 4) [1..4] 1
Project name (default: sample-project):
Source package (default: sample.project):
--Install an extension called Java Extension Pack in VSCode. (Don't forget to restart VS Code)
--Edit build.gradle
build.gradle
plugins {
id 'java'
id 'application'
id 'eclipse' //Add this. To output the classpath for auto-completion.
}
repositories {
jcenter()
}
dependencies {
implementation 'com.google.guava:guava:29.0-jre'
testImplementation 'junit:junit:4.12'
}
mainClassName = 'sample.project.App'
//Add below from here
//Measures against garbled characters
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
//Have a single executable jar containing dependent libraries created.
jar {
manifest { attributes 'Main-Class': mainClassName }
from configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
--Output classpath
Be sure to run it after changing the dependencies.
gradle eclipse
You should now be able to do auto-completion.
It's already in the Java Extension Pack, so you can do it with Shift + Alt + F
.
If you want to make detailed settings, press F1
and enter ʻOpen Java formatter settingsto enter. After that, you will be asked to enter the path of the configuration file, but since it is not there, enter as it is. At the bottom right, you will see something like "'eclipse-formatter.xml' does not exist. Do you want to create it?", So press
Yes`.
And now that eclipse-formatter.xml is created, let's set it as you like!
I am changing the following so that the line break code in the method chain etc. is not made into one line at the time of automatic formatting
eclipse-formatter.xml
<!--Change true to false-->
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>
Restart VS Code after setting
Recommended Posts