问题
I am working on a gradle project. I have no issue building and running my project with gradle and seeing the output. However, in my both NetBeans and Eclipse the following lines are underlined in red:
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import javax.persistence.criteria.CriteriaBuilder;
The error is:
package xxx does not exist
This is actually quite annoying because it means I have no auto-completion and no real ability to detect legitimate build errors before trying to build.
Restarting the IDE does not help. Clean and build does not help. I installed the gradle plugin too, but nothing changed.
How can I change my settings so that NetBeans recognizes this as a gradle project and picks up my dependencies?
My build.gradle
, as requested in the comments:
apply plugin: 'java-library'
apply plugin: 'application'
mainClassName = 'server.Server'
repositories {
jcenter()
}
dependencies {
implementation 'org.hibernate:hibernate-core:5.2.10.Final'
implementation 'org.postgresql:postgresql:42.0.0'
implementation 'com.sparkjava:spark-core:2.5.5'
implementation 'com.google.code.gson:gson:2.8.0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.7.22'
}
Edit
The build script works fine normally, but when I check the project into source control and then check it out on another machine, the problem shows up. I meant to be very clear about that in my original post, but I think I failed.
回答1:
I faced the same issue some time ago. The only thing helped to me was clearing NetBeans cache. On Windows operating system it is located under C:\Users\<user>\AppData\Local\NetBeans\Cache
folder, on Linux operating systems under /home/<user>/.cache/netbeans
one. So, what I did was closed NetBeans, deleted folders inside the specified one, and started NetBeans again.
回答2:
This is really stupid, but I was trying to import the project as an eclipse project. If you just clone the project and open it normally (with the NetBeans gradle plugin installed) it will work.
来源:https://stackoverflow.com/questions/43837698/i-can-build-and-run-my-project-but-my-ide-keeps-showing-errors