Recently, I've been trying various things to unify Java development into VS Code.
Some people were already addicted to the same thing, but as a memo to myself.
For the time being, my environment set is posted, but the framework can be anything. (Reproduced in VSCode, Gradle environment.)
Define additional dependent libraries in the dependencies of build.gradle
. For example, let's add a dependency on Doma2 to our Spring Boot application.
build.gradle
// ...abridgement
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
//Added dependency on Doma2
annotationProcessor "org.seasar.doma.boot:doma-spring-boot-starter:1.4.0"
}
// ...abridgement
After downloading the dependency library, display the dependencies tree. (To confirm that the Doma2 dependency has been added)
// ...abridgement
| \--- org.seasar.doma.boot:doma-spring-boot-autoconfigure:1.4.0
| +--- org.seasar.doma.boot:doma-spring-boot-core:1.4.0
| | +--- org.seasar.doma:doma-core:2.35.0
| | +--- org.springframework:spring-context:4.3.25.RELEASE -> 5.2.7.RELEASE (*)
| | +--- org.springframework:spring-jdbc:4.3.25.RELEASE -> 5.2.7.RELEASE (*)
| | \--- org.springframework.data:spring-data-commons:1.13.23.RELEASE -> 2.3.1.RELEASE
| | +--- org.springframework:spring-core:5.2.7.RELEASE (*)
| | +--- org.springframework:spring-beans:5.2.7.RELEASE (*)
| | \--- org.slf4j:slf4j-api:1.7.26 -> 1.7.30
| +--- org.springframework:spring-jdbc:4.3.25.RELEASE -> 5.2.7.RELEASE (*)
| \--- org.springframework.boot:spring-boot-autoconfigure:1.5.22.RELEASE -> 2.3.1.RELEASE (*)
// ...abridgement
As a test, when I try to define the Entity class, the event that the automatic completion of annotations such as @ Entity
and @ Table
does not work occurs.
EmployeeEntity.java
// ...abridgement
@Getter
@Setter
// @Entity <-Auto-completion doesn't work!
// @Table(name = "employees") <-Auto-completion doesn't work!
public class EmployeeEntity {
private Integer id;
private String name;
}
VSCode's Java import completion reads .classpath
like Eclipse, so you can regenerate .classpath
when you add the dependent libraries.
build.gradle
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'eclipse' //add to
}
// ...abridgement
$ ./gradlew eclipse
BUILD SUCCESSFUL in 1s
3 actionable tasks: 3 executed
OK!
After all it is a point that I personally like that it is lightweight.
However, in development cases such as loading user libraries, it seems that it is not yet a complete migration because it can only be handled by Eclipse.
-Procedure (Windows 10) that I did when I prepared the environment of gradle + Java with VS Code
Recommended Posts