Zealot
Zealot

Reputation: 21

Why doesn't vs code import new dependencies I add that are different from the gradle init default configuration?

I'm using gradle 7.02 (and used the gradle init with the option to create a single java project using groovy as build language) -VS Code version:

Version: 1.46.1 Commit: cd9ea6488829f560dc949a8b2fb789f3cdc05f5d Date: 2020-06-17T21:17:14.222Z (11 mos ago) Electron: 7.3.1 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Darwin x64 18.7.0

I have the following plugins:

-Debugger for Chrome -Debugger for Java -ESLint -Gradle Language Support -Java Extension Pack -Java Test Runner -Language Support for Java by redhat -Maven for Java -Project Manager for Java

When I run a task in gradle to show the cache it shows the correct dependencies:

Task :app:showMeCache /Users/xxx/.gradle/caches/modules-2/files-2.1/org.projectlombok/lombok/1.18.20/18bcea7d5df4d49227b4a0743a536208ce4825bb/lombok-1.18.20.jar /Users/xxx/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/30.0-jre/8ddbc8769f73309fe09b54c5951163f10b0d89fa/guava-30.0-jre.jar /Users/xxx/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.12.3/7275513412694a1aafd08c0287f48469fa0e6e17/jackson-annotations-2.12.3.jar /Users/xxx/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.12.3/d6153f8fc60c479ab0f9efb35c034526436a4953/jackson-databind-2.12.3.jar /Users/xxx/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.12.3/deb23fe2a7f2b773e18ced2b50d4acc1df8fa366/jackson-core-2.12.3.jar /Users/xxx/.gradle/caches/modules-2/files-2.1/com.google.guava/failureaccess/1.0.1/1dcf1de382a0bf95a3d8b0849546c88bac1292c9/failureaccess-1.0.1.jar /Users/xxx/.gradle/caches/modules-2/files-2.1/com.google.guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/b421526c5f297295adef1c886e5246c39d4ac629/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar /Users/xxx/.gradle/caches/modules-2/files-2.1/com.google.code.findbugs/jsr305/3.0.2/25ea2e8b0c338a877313bd4672d3fe056ea78f0d/jsr305-3.0.2.jar /Users/xxx/.gradle/caches/modules-2/files-2.1/org.checkerframework/checker-qual/3.5.0/2f50520c8abea66fbd8d26e481d3aef5c673b510/checker-qual-3.5.0.jar /Users/xxx/.gradle/caches/modules-2/files-2.1/com.google.errorprone/error_prone_annotations/2.3.4/dac170e4594de319655ffb62f41cbd6dbb5e601e/error_prone_annotations-2.3.4.jar /Users/xxx/.gradle/caches/modules-2/files-2.1/com.google.j2objc/j2objc-annotations/1.3/ba035118bc8bac37d7eff77700720999acd9986d/j2objc-annotations-1.3.jar

When I ran the debug it showed it downloaded the dependencies when I ran gradle clean build --refresh-dependencies -debug

I was able to get the dependencies to work if I did a simple project using gradle init but for some reason when you do application vs code doesn't add the dependencies under java projects->Project and External Dependencies.

This is the build file for my app:

  /*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java application project to get you started.
 * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
 * User Manual available at https://docs.gradle.org/7.0.2/userguide/building_java_projects.html
 */

plugins {
    // Apply the application plugin to add support for building a CLI application in Java.
    id 'application'
    
}

apply plugin: 'java'

repositories {
    // Use Maven Central for resolving dependencies.
    mavenCentral()
}

dependencies {
    // Use JUnit Jupiter API for testing.
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'

    // Use JUnit Jupiter Engine for testing.
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'

    // This dependency is used by the application.
    implementation 'com.google.guava:guava:30.0-jre'

    implementation 'com.fasterxml.jackson.core:jackson-core:2.12.3'
    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.12.3'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
    compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.20'

}

application {
    // Define the main class for the application.
    mainClass = 'query.App'
}

tasks.named('test') {
    // Use junit platform for unit tests.
    useJUnitPlatform()
}

task showMeCache doLast() {
    configurations.compileClasspath.each { println it }
}

This is the build file for the simple project that does download the dependencies properly in vs code:

    apply plugin: 'java'


defaultTasks 'clean', 'compileJava'

repositories {
    mavenCentral()
}

dependencies{
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-api:5.7.1'
    implementation 'com.fasterxml.jackson.core:jackson-core:2.12.3'
    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.12.3'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
}

test {
    useJUnitPlatform()
}

I've searched online for solutions for vs code but can't seem to find anyone with my issue. What am I doing wrong?

Upvotes: 1

Views: 5832

Answers (1)

Molly Wang-MSFT
Molly Wang-MSFT

Reputation: 9521

but for some reason when you do application vs code doesn't add the dependencies under java projects->Project and External Dependencies.

After adding an dependency, there would be a notification popping up to ask you

A build file was modified. Do you want to synchronize the Java classpath/configuration?

Click Now, your project will be rebuilt, then the dependency would be added to Project and External Dependencies. If not there, after rebuilding project, click the refresh button:

enter image description here

Upvotes: 1

Related Questions