我可以构建并运行我的项目,但我的IDE不断显示错误 [英] I can build and run my project but my IDE keeps showing errors

查看:125
本文介绍了我可以构建并运行我的项目,但我的IDE不断显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个gradle项目。我没有问题使用gradle构建和运行我的项目并查看输出。但是,在我的NetBeans和Eclipse中,以下行以红色下划线:

  import org.hibernate.Session; 
import org.hibernate.SessionFactory;
导入org.hibernate.cfg.Configuration;
import javax.persistence.criteria.CriteriaBuilder;

错误是:


package xxx不存在

这实际上很烦人,因为这意味着我没有自动完成,也没有真正的能够在尝试构建之前检测到合法的构建错误。



重新启动IDE并没有帮助。清理和构建不起作用。



如何更改我的设置,以便NetBeans将此识别为Gradle项目并提取我的依赖关系?



我的 build.gradle ,如评论中所要求的那样:

<$应用插件:'java-library'
apply插件:'application'

mainClassName ='server.Server'

存储库{
jcenter()
}

依赖项{
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'
}

编辑

构建脚本正常工作正常,车将该项目输入到源代码控制中,然后在另一台机器上检查它,问题就会显现出来。我的意思是在我原来的帖子中非常清楚,但我认为我失败了。 解决方案

这真的很愚蠢,但我试图将项目导入为eclipse项目。如果您只克隆项目并正常打开它(安装了NetBeans gradle插件),它就可以工作。


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.

解决方案

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.

这篇关于我可以构建并运行我的项目,但我的IDE不断显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆