Vscode-java: maven does not resolve all the dependencies

Created on 9 Apr 2019  路  11Comments  路  Source: redhat-developer/vscode-java

Compilation error in VSCode:
The import javax.annotation.PostConstruct cannot be resolved
Looking at the effective pom, the following dependency is present:

     <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
        <version>1.3.2</version>
      </dependency>
Environment
  • Operating System: Fedora 29
  • JDK version: OpenJDK Runtime Environment (build 1.8.0_201-b09)
  • Visual Studio Code version: 1.33
  • Java extension version: 0.42.1
Steps To Reproduce
  1. Import this project: https://github.com/kiegroup/optaweb-employee-rostering
Maven

Most helpful comment

@dmarrazzo could you try the following:

  • add
"java.home": "/usr/lib/jvm/java-1.8.0-openjdk/",

to VS Code settings

  • close VS Code
  • run
rm -rf /home/donato/.config/Code/User/workspaceStorage
  • start VS Code

All 11 comments

Works for me. You can try to right-click on your project's pom and try to "update project configuration", if that doesn't work then call the "Clean the Java language server workspace" command

Hi @fbricon, thank you for the prompt reply.
I did the update and clean... but nothing.
the following works:

  • mvn clean compile
  • eclipse import

May I collect more info from my env?

Hi @fbricon here the log.

The only error that I see is the following:
!ENTRY org.eclipse.jdt.ls.core 4 0 2019-04-09 23:21:57.341
!MESSAGE
!STACK 0
org.eclipse.jface.text.BadLocationException
at org.eclipse.jface.text.ListLineTracker.getLineOffset(ListLineTracker.java:197)
at org.eclipse.jface.text.AbstractLineTracker.getLineOffset(AbstractLineTracker.java:160)
at org.eclipse.jface.text.AbstractDocument.getLineOffset(AbstractDocument.java:876)
(...)

log.zip

Does it help?

Maybe you are interested even to other files in the directory:

metadata_dir.zip

Hi @fbricon, any hints? Did you have the chance to look into the logs?
I'm quite surprised that you cannot reproduce the error. I have installed everything from scratch, cleaning all the user data (.config, etc). But I run always in the same problem.
Which OS and JVM are you using?

Thank you

@dmarrazzo could you try the following:

  • add
"java.home": "/usr/lib/jvm/java-1.8.0-openjdk/",

to VS Code settings

  • close VS Code
  • run
rm -rf /home/donato/.config/Code/User/workspaceStorage
  • start VS Code

Hello @snjeza, this solved the problem!
So the issue was due to a wrong javac (I suspect jdk11).

Thank you very much!

@dmarrazzo your server logs show you're using java.version=11.0.2. Alternatively, if you open vscode's developer tools, you'll see which JDK binary is used to launch the language server.

Some recent jdks cause some issues with some annotation processors, so it might be sometimes safer to use 1.8

Thank you @fbricon
My confusion was caused by the fact that alternative command admits two configuration for java and javac so I thought I was running 1.8 but the javac was actually on 11.

@snjeza Thank you so much! this fixed my issue too. Confirmed this also fixes unresolved dependencies in my Gradle sparkjava web app project (with Kotlin DSL). Must have been because I just switched from oracle's jdk 8 to OpenJDK 11, due to their changes in support. This also fixed up the Java Dependency Explorer extension and I can now see sparkjava and jetty jars listed under my project tree.

Was this page helpful?
0 / 5 - 0 ratings