redhat-developer / vscode-java

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

[Java] The import javax.persistence.Entity cannot be resolved #397

Closed sombriks closed 6 years ago

sombriks commented 6 years ago

This is a gradle-based project, i am developing a sample spring-boot app.

https://github.com/sombriks/gm-sample-worklog/tree/master/gm-sample-worklog-service

Every other import seems to work just fine, however javax.persistence package isn't. Lombok doesn't seems to be recognized as well.

It's strange because when i command "gradle bootRun" it works perfectly.

Environment
Steps To Reproduce
  1. checkout project
  2. open gm-sample-worklog-service with code
  3. open "User" class or any other containing JPA annotations
gorkem commented 6 years ago

Did you try https://github.com/redhat-developer/vscode-java/wiki/Lombok-support for Lombok?

sombriks commented 6 years ago

hi @gorkem thanks for the quick answer.

I didn't faced the lack of autocomplete for lombok augmentation, but i'll set it up.

But i think the import issue isn't related to this lack of configuration. I had that with JPA annotations before i added Lombok.

sombriks commented 6 years ago

Hi @gorkem ,

i've set up lombok at settings.json as suggested but the import issue remains, see the print.

captura de tela de 2017-12-24 23-48-36

as far as i investigated, it seems related to secondary dependencies.

for example, the entire javax.persistence package comes from hibernate-jpa-2.1-api-1.0.0.Final, however i do not depend on it directy in my build.gradle. i depend on spring-boot-starter-data-jpa, and that one call hibernate-jpa to the dependency tree.

sombriks commented 6 years ago

Hi again,

turns out this is not really a issue.

since vscode-java relies on eclipse configs, every time when a new dependency gets added to build.gradle, the "eclipse" task must run again.

downloaded eclipse, and the project setup where broken there too. then i ran gradle cleanEclipse and gradle eclipse and the classpath was generated again.

it's working perfectly.

fbricon commented 6 years ago

From the readme:

Java:Update Project configuration (Shift+Alt+U): is available when the editor is focused on a Maven pom.xml or a Gradle file. It forces project configuration / classpath updates (eg. dependency changes or Java compilation level), according to the project build descriptor.

and the matching preference:

The following settings are supported: ... java.configuration.updateBuildConfiguration : Specifies how modifications on build files update the Java classpath/configuration. Supported values are disabled (nothing happens), interactive (asks about updating on every modification), automatic (updating is automatically triggered).

Prikalel commented 2 years ago

For people with the same issue: ctrl+shift+P & Clean java language server workspace. 😉

vaidik commented 1 year ago

For people with the same issue: ctrl+shift+P & Clean java language server workspace. 😉

This is what worked for me after spending a couple of hours to resolve this issue. Thanks @Prikalel !