redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.08k stars 442 forks source link

Support additional Gradle configurations #1809

Open NiklasRosenstein opened 3 years ago

NiklasRosenstein commented 3 years ago

Our projects often times have integration tests and we use a Gradle configuration called integrationTest. The source for these tests is usually located in a src/integrationTest/java directory. Example:

my-subproject/
  build.gradle
  src/
    integrationTest/
      java/
        com/ ...
    main/
      java/
        com/ ...
build.gradle
settings.gradle

In my-subproject/build.gradle the dependencies are defined akin to

dependencies {
    implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
    integrationTestImplementation 'org.junit.jupiter:junit-jupiter'
}

Right now, this means that IntelliSense will not be able to find symbols from the junit-jupiter dependency while editing code in the integrationTest directory. It appears to treat these source files as part of the default configuration.

testforstephen commented 3 years ago

Since you're using custom configurations/dependencies in your build.gradle, and the gradle tooling buildship used by vscode java extension doesn't recognize it by default. You have to add a line like eclipse.classpath.plusConfigurations << configurations.integrationTestImplementation to your build.gradle. Learn more from FAQ at buildship and https://github.com/eclipse/buildship/issues/371.