redhat-developer / vscode-java

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

Java language support for embedded Gradle plugin #978

Open a01fe opened 5 years ago

a01fe commented 5 years ago

I have a Gradle project with an embedded plugin in buildSrc that has Java code in buildSrc/srcmain/my/package/Foo.java. When I open these Java files, a "Foo.java isn't on the classpath" notification pops up and things like Oragnize Imports and javadoc hovers don't work.

It would be awesome if vscode-java would recognize buildSrc in a Gradle project so language support would work in plugin source code.

Environment
Steps To Reproduce
  1. Create a Gradle project and open it in vscode
  2. Add Java source files to buildSrc/package/Foo.java
  3. Open the Java source files
Current Result

No language support available

Expected Result

Working language support

snjeza commented 5 years ago

@a01fe you can try the following build.gradle:

plugins {
    id 'java'
    id 'eclipse'
}

repositories {
    jcenter()
}
dependencies {
}
sourceSets {
    main {
        java {
            srcDirs 'src/main/java', 'buildSrc/srcmain'
        }
    }
}
stefanrybacki commented 3 years ago

@a01fe you can try the following build.gradle:

plugins {
    id 'java'
    id 'eclipse'
}

repositories {
    jcenter()
}
dependencies {
}
sourceSets {
    main {
        java {
            srcDirs 'src/main/java', 'buildSrc/srcmain'
        }
    }
}

But this mixes normal source code with isolated plugin code of buildsrc which might have completely different dependencies etc. So this is not a viable solution.

Interestingly it works in eclipse though. There it is just another gradle project imported.

CsCherrYY commented 2 years ago

actually it's a missing feature in buildship, see: https://github.com/eclipse/buildship/issues/1126#issuecomment-1004643907. vscode-java can support importing buildSrc once buildship supports it.