redhat-developer / vscode-java

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

vscode-java fails to build project with pom-type dependency #3555

Open kalaracey opened 5 months ago

kalaracey commented 5 months ago

I am attempting to follow https://www.graalvm.org/latest/reference-manual/python/ in VSCode, but the Java Language Support for VSCode appears to be having some difficulty. Namely, it thinks the project cannot be built, while ./gradlew build succeeds just fine.

Environment
Steps To Reproduce
  1. git clone https://github.com/kalaracey/graalpy-vscode-issue.git
  2. Open graalpy-vscode-issue in VSCode
  3. Wait for the automatic "Opening Java Projects" to finish

Java Language Server log

Current Result

VSCode's Problems tab has two problems:

Screenshot 2024-03-29 at 11 15 05 AM
Expected Result

No problems, given that ./gradlew build succeeds.

Additional Informations

/Users/kal/.gradle/caches/modules-2/files-2.1/org.graalvm.polyglot/python-community/23.1.2/2534a71914ae30007251d1f91f67bb5b5b3431d/python-community-23.1.2.pom is the only file in its directory.

Outputs from various VSCode tasks:

kalaracey commented 5 months ago

FWIW, I noticed that when I Java: Configure Java Runtime, the type of project app is "Unmanaged folder", and not "Gradle" as I would have expected, but I don't know how to change that. Not sure if that's related.

Screenshot 2024-03-29 at 11 27 15 AM
kalaracey commented 5 months ago

Poking around /Users/kal/.gradle/caches/modules-2/files-2.1, I noticed something peculiar about org.graalvm.polyglot/python-community: it only includes a pom file, and no jars, unlike other dependencies.

I noticed that in the Maven setup for embedded GraalPy (see also here), <type>pom</type> is specified, i.e. the python-community is a "pom-type" dependency.

Searching for [jdt "pom dependency"] on Google reveals [jira] [Closed] (MCOMPILER-544) ZipException: zip END header not found on POM dependency with Eclipse compiler:

ZipException: zip END header not found on POM dependency with Eclipse compiler

There is an impedance matching issue between Maven Compiler Plugin, plexus-compiler-eclipse, and eclipse.jdt.core. m-c-p adds POM dependency's POM file to classpath, which makes it through plexus-compiler-eclipse to JDT and that prints an exception ZipException: zip END header not found. Arguably, m-c-p should not be adding non-JAR, non-wildcard-directory path to classpath for the compiler.

The issue seems to have been tracked in https://github.com/apache/maven-compiler-plugin/pull/198 and https://github.com/codehaus-plexus/plexus-compiler/issues/302.

kalaracey commented 5 months ago

It looks like the issue was reported to the Eclipse JDT project (https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1274) but they closed the issue without a fix, and the fix was made in the Maven Compiler Plugin (see link in previous comment). IIUC, that would mean that a fix similar to https://github.com/apache/maven-compiler-plugin/pull/198 would be needed in vscode-java.

As mitigation, I wonder if there is a way to get vscode-java to ignore certain dependencies, like the pom-type python-community dependency.

kalaracey commented 5 months ago

There is another Eclipse JDT issue related to the Zip problem that is still open: https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1578

kalaracey commented 5 months ago

Ok I have found a partial mitigation but it is not complete. I changed

    implementation("org.graalvm.polyglot:python:23.1.2")

in build.gradle.kts to

    implementation("org.graalvm.polyglot:python:23.1.2") {
        exclude(group = "org.graalvm.polyglot", module = "python-community")
    }

Running ./gradlew run still works (it prints "Hello Python!") but there are now some scary looking errors that indicate possible trouble with anything more complicated than a Hello World program:

[python::PythonContext] WARNING: could not determine Graal.Python's core path - you may need to pass --python.CoreHome.
[python::PythonContext] WARNING: could not determine Graal.Python's sys prefix path - you may need to pass --python.SysPrefix.
[python::PythonContext] WARNING: could not determine Graal.Python's standard library path. You need to pass --python.StdLibHome if you want to use the standard library.
[python::PythonContext] WARNING: could not determine Graal.Python's C API library path. You need to pass --python.CAPI if you want to use the C extension modules.
[python::PythonContext] WARNING: could not determine Graal.Python's C API library path. You need to pass --python.CAPI if you want to use the C extension modules.
[python::PythonContext] WARNING: could not determine Graal.Python's JNI library. You need to pass --python.JNILibrary if you want to run, for example, binary HPy extension modules.
[python::PythonContext] WARNING: could not determine Graal.Python's C API library path. You need to pass --python.CAPI if you want to use the C extension modules.
[python::PythonContext] WARNING: could not determine Graal.Python's C API library path. You need to pass --python.CAPI if you want to use the C extension modules.
[python::PythonContext] WARNING: could not determine Graal.Python's JNI library. You need to pass --python.JNILibrary if you want to run, for example, binary HPy extension modules.
kalaracey commented 5 months ago

Adding /Users/kal/.gradle/caches/modules-2/files-2.1/org.graalvm.polyglot/python-community/23.1.2/2534a71914ae30007251d1f91f67bb5b5b3431d/python-community-23.1.2.pom to java.project.referencedLibraries.exclude has no effect.

kalaracey commented 5 months ago

Ok here might be a better mitigation. It seems like the pom dependencies are just placeholders to pull in other, real dependencies. So I inspected the dependencies of

and determined which ones looked like they were necessary. In build.gradle.kts I replaced

    implementation("org.graalvm.polyglot:python:23.1.2")

with

    implementation("org.graalvm.python:python-language:23.1.2")
    implementation("org.graalvm.python:python-resources:23.1.2")
    implementation("org.graalvm.truffle:truffle-runtime:23.1.2")

and the entries in the Problems pane that I reported appear to have gone away, and there is no discernible difference in the output of ./gradlew run.

It would still be great if the underlying problem of adding these pom-only dependencies to the class path (IIUC) could be fixed.

kalaracey commented 5 months ago

Interestingly, vscode-java does not appear to suffer from this issue when using the example GraalPy Maven project (which can be set up with a single command), indicating the issue may be related to Gradle or how vscode-java is using Gradle.