简体   繁体   中英

Gradle project in eclipse builds fine but java files show compilation error

This is my first gradle project. I am using Buildship eclipse plugin for gradle. In my build.gradle file, I have below plugins applied -

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'war'
apply plugin: 'com.bmuschko.tomcat'

All the relevant dependencies are defined as compile as below -

.
.
compile ("org.hibernate:hibernate-entitymanager:${hibernateVer}")
compile ("org.hibernate:hibernate-core:${hibernateVer}")
compile ("org.hibernate:hibernate-validator:${hibernateValVer}")

compile ("org.slf4j:slf4j-api:${slf4jVer}")
compile ("org.slf4j:slf4j-log4j12:${slf4jVer}")
.
.

The project builds and runs successfully using tomcatRun command as well. But the eclipse is showing compilation errors on my imports in java files, saying that the dependencies can not be resolved.

I tried Project->Clean and then refresh, but still stuck. What can i do to remove these compilation errors? Thanks in advance.

Right click on your Project-> Goto Gradle-> Refresh Gradle Project . Eclipse would pick the jars downloaded by gradle now.

Removing the project from workspace and importing it again as a gradle project fixed the issue for me. Maybe somewhere down the path I have done something that has removed the "gradle" nature of the project.

In my case, after successful build, Go to Package Explorer (not Project Explorer) -> Press ctrl+A (select all) -> right click & refresh. I think it will help to resolve all the dependencies and all the errors in eclipse will be gone. Hope it helps!

For what it's worth, I had to remove the following files from my web client project under .settings :

org.eclipse.jdt.core.prefs
org.eclipse.jdt.apt.core.prefs

Then I also had to manually modify .settings/gradle.prefs to properly define the following:

projectPath (was ":" changed to ":projectNameClient")
connection_project_dir  (points to the EAR project path)

我不得不从 STS 中删除项目并作为 Gradle 导入 - 解决了这个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM